当前位置:文档之家› Android保存网络图片到本地与读取

Android保存网络图片到本地与读取

//保存网络图片到本地 第一个参数是图片名称 第二个参数为需要保存的bitmap
public void saveImg(String imgName, Bitmap bitmap) {
File file = new File("/sdcard/", imgName + ".png");
try {
FileOutputStream out = new FileOutputStream(file);
https://www.doczj.com/doc/c64071820.html,press(https://www.doczj.com/doc/c64071820.html,pressFormat.PNG, 90, out);
out.flush();
out.close();
Log.i("", "成功");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

}

//读取本地图片 参数路径
private Bitmap getDiskBitmap(String pathString) {
Bitmap bitmap = null;
try {
// File file = new File(pathString);
// if (file.exists()) {
bitmap = BitmapFactory.decodeFile(pathString);
// }
} catch (Exception e) {
}

return bitmap;
}

相关主题
文本预览
相关文档 最新文档