【发布时间】:2020-11-16 06:43:23
【问题描述】:
我从自定义相机保存图像:
public String getFilename() {
File file = new File(Environment.getExternalStorageDirectory().getPath(), "Products/Images");
if (!file.exists()) {
file.mkdirs();
}
String uriSting = (file.getAbsolutePath() + "/" + System.currentTimeMillis() + ".jpg");
return uriSting;
}
现在:
public String saveImage(Bitmap bitmap) {
FileOutputStream out = null;
String filename = getFilename();
try {
out = new FileOutputStream(filename);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
} catch (FileNotFoundException e) {
Log.e("Error",e.toString());
e.printStackTrace();
return "";
}
return filename;
}
我在保存图片后在 exifInterface 中使用这个文件名
exif = new ExifInterface(filePath);
但每次都显示在我的日志中Raw image not detected,Exif: 0
【问题讨论】:
-
file.mkdirs();调整您的代码。检查 mkdirs 的返回值,如果为 false,则停止。返回空值。停止并显示 toast 以通知用户。
标签: android