[英]Android bitmap saving error. saving image is wrong , update gallery after saving image to sd card
我创建了一个函数来保存从图库中选择的图像。我意识到第一次保存图像时可以。但是如果再次启动该过程,似乎图像已保存(具有相同的名称)但图像在资源管理器中不会改变。它只是保留旧的位图图像。我在两个不同的设备上进行了测试,但结果相同。实际上,在 Infinix hot 7 上但结果相同。
public static String saveImage(Bitmap bitmap, File[] folders, File file, Context context) {
for (File folder:folders) {
if (!folder.exists()) {
folder.mkdirs();
}
}
if (file.exists ()) {
file.delete();
}
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, bytes);
try {
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
你可以看到我选择了一张绿色自然的照片,但它注册了一张老红树照片
将图像保存在图库中后,您应该将图像更新到图库和文件浏览器的系统
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(myNewFile)));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.