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

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

//保存网络图片到本地 第一个参数是图片名称 第二个参数为需要保存的bitmap
public void saveImg(String imgName, Bitmap bitmap) {
File file = new File("/sdcard/", imgName + ".png");
try {
FileOutputStream out = new FileOutputStream(file);
press(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;
}

相关文档
最新文档