我正在使用 Firebase 来存储 Android 应用的图像。然后,这些图像会出现在我的应用程序的回收 View 中。这一切都很好,但是,某些图像会出现横向。特别是那些用 Galaxy S7 拍摄的照片。
我知道我需要从图像中获取 exif 信息,但是当我尝试时出现文件未找到错误,我该怎么办?
private int getImageOrientation(String imagePath){
int rotate = 0;
try {
File imageFile = new File(imagePath);
ExifInterface exif = new ExifInterface(imageFile.getAbsolutePath());
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
}
} catch (Exception e) {
e.printStackTrace();
}
return rotate;
}
W/System.err: java.io.FileNotFoundException: /https:/firebasestorage.googleapis.com/v0/b/pickit-d193d.appspot.com/o/posts%2Ff12e73ad-9bc5-4485-90e5-927dbf8539a5.jpg?alt=media&token=9f92c0d7-0518-4721-a7b5-235c1fb3cc76 (No such file or directory)
我只需要它来返回图像旋转的程度,但它总是返回 0,因为它会抛出“文件未找到”表达式。任何帮助将不胜感激。
最佳答案
https:/firebasestorage.googleapis.com/v0/b/pickit-d193d.appspot.com/o/posts%2Ff12e73ad-9bc5-4485-90e5-927dbf8539a5.jpg?alt=media&token=9f92c0d7-0518 -4721-a7b5-235c1fb3cc76
是 HTTPS URL。它不是文件系统上的文件。
下载文件,然后使用 the AndroidX edition of ExifInterface
检查它。
或者,如果您要在 ImageView
中显示这些图像,请使用 Glide 或 Picasso 等图像加载库,它们在显示图像时应考虑 EXIF 方向 header 。
关于java - 为什么 Android 上的 ExifInterface 会出现“文件未找到”错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56726173/