【发布时间】:2018-08-20 22:04:33
【问题描述】:
我知道我可以在 DCIM 中创建一个文件夹,如果其中有文件,该目录将显示为专辑名称。我可以很好地创建目录,在这种情况下,我将目录称为“ThoughtCast”。
不过,我尝试保存一个 PNG 文件,但它确实没有出现。
这是我的代码:
public void savebitmap(Bitmap bmp) throws IOException {
String file_path =Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM) + File.separator + "ThoughtCast/";
File dir = new File(file_path);
if(!dir.exists())
dir.mkdirs();
File file = new File(dir, "sketchpad" + ".png");
FileOutputStream fOut = new FileOutputStream(file);
bmp.compress(Bitmap.CompressFormat.PNG, 85, fOut);
fOut.flush();
fOut.close();
}
任何帮助将不胜感激。谢谢
【问题讨论】:
-
运行时权限?
-
String[] PERMISSIONS = {android.Manifest.permission.WRITE_EXTERNAL_STORAGE} 处于活动状态。
-
I try saving a PNG file however, and it does not appear.它应该出现在哪里?为什么不先判断位图是否确实保存为文件? -
它应该出现在我的 ThoughtCast 文件夹中。
-
你确定catch块中没有异常
标签: android android-studio android-bitmap android-gallery