I am using Firebase to store images for my android app. The images then appear in my app in a recycler view. This all works fine, however, certain images appear sideways. Specifically those taken with a Galaxy S7.
I know that I need to get the exif information from the images but when I try I get a file not found error what can I do?
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)
I just need this to return how much the image is rotated but it always returns 0 since it throws a File not found expression. Any help would be greatly appreciated.
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
is an HTTPS URL. It is not a file on the filesystem.
Download the file, then use the AndroidX edition of ExifInterface
to examine it.
Or, if you will be showing these images in an ImageView
, use an image-loading library like Glide or Picasso, which should take the EXIF orientation headers into account when displaying the images.