【发布时间】:2015-05-08 03:51:34
【问题描述】:
正如您在下面的代码中看到的,我将位图保存到公共图片目录中。我还提供了存储中图像的屏幕截图,作为图像正在保存的进一步证据。
问题是图像不会显示在照片应用程序中,直到我重新启动手机。我检查了其他应用程序,这些图片立即出现。如果我打开图像,我也无法像其他图片一样编辑它(例如添加效果)。
Bitmap b = Bitmap.createScaledBitmap(mBitmap, width, height, false);
Long uuid = UUID.randomUUID().getMostSignificantBits();
File path = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES + "/test");
if(!path.exists() && !path.isDirectory()){
path.mkdirs();
}
Log.i("Directory:", path.toString());
File file = new File(path, "test_" + uuid + ".jpg");
if (file.exists()){
file.delete();
}
FileOutputStream out = null;
try {
out = new FileOutputStream(file);
b.compress(Bitmap.CompressFormat.JPEG, 80, out);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
});
【问题讨论】:
-
看看[this][1]堆栈溢出链接[1]:stackoverflow.com/questions/20001662/…
-
@AnandMakwana 谢谢。它工作:)
标签: java android file bitmap save