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.
So the answer that I implemented works for me but I am not sure it will work in all cases. So when I am creating an image I set a boolean value to check if the height is more than the width. Then when I am loading the image in picasso I have:
Picasso.get()
.load(imageURL_1)
.fit()
.rotate(post.isRotated()?0:90)
.transform(new RoundedCornersTransformation(30,30))
.into(imageView1);
Like I said this only works if the image is rotated counter clockwise 90 degrees. If there is a better fix I welcome your answers, but this is the best I can do without access to EXIF information.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.