安卓开发——如何将Bitmap保存为本地图片

来源:互联网 发布:巨人的陨落读后感 知乎 编辑:程序博客网 时间:2024/05/13 04:20

原文地址:http://www.apkbus.com/blog-17085-54589.html

public boolean saveMyBitmap(Bitmap bmp, String bitName) throws IOException {  File dirFile = new File("./sdcard/DCIM/Camera/");  if (!dirFile.exists()) {   dirFile.mkdirs();  }  File f = new File("./sdcard/DCIM/Camera/" + bitName + ".png");  boolean flag = false;  f.createNewFile();  FileOutputStream fOut = null;  try {   fOut = new FileOutputStream(f);   bmp.compress(Bitmap.CompressFormat.PNG, 100, fOut);   flag = true;  } catch (FileNotFoundException e) {   e.printStackTrace();  }  try {   fOut.flush();  } catch (IOException e) {   e.printStackTrace();  }  try {   fOut.close();  } catch (IOException e) {   e.printStackTrace();  }  return flag; }


0 0
原创粉丝点击