【发布时间】:2018-03-19 09:13:01
【问题描述】:
我正在使用位图。但是在捕获图像后,我试图将图像保存在外部存储中,它变得模糊了。请给我解决方案。 这是我的代码 -
public void saveImageToExternalStorage() {
String root =Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();
File myDir = new File(root + "/saved_images");
myDir.mkdirs();
Random generator = new Random();
int n = 10000;
n = generator.nextInt(n);
String fname = "Image-" + n + ".jpg";
File file1 = new File(myDir, fname);
if (file1.exists())
file1.delete();
try {
FileOutputStream out = new FileOutputStream(file1);
finalBitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
out.flush();
out.close();
}
catch (Exception e) {
e.printStackTrace();
}
// Tell the media scanner about the new file so that it is
// immediately available to the user.
MediaScannerConnection.scanFile(this, new String[] { file1.toString() }, null,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
}
});
}
}
【问题讨论】:
-
什么是
blured? -
压缩图像时,它会保存到图库但无法加载。@greenapps
-
到画廊?
I am trying to save image in External storage???在你的帖子中,我没有读到任何关于无法加载的信息。你不能写一个更好的帖子吗?什么是模糊的? -
我更正了我的帖子。@greenapps
-
logcat 显示什么错误?