Saved Image orientation in Gallery using ExifInterface

90 views
Skip to first unread message

Haider Saleem

unread,
Nov 1, 2021, 4:19:31 AM11/1/21
to Android CameraX Discussion Group
Hi!

I'm trying to flip image using ExifInterface, where I need to flip along the short edge. (eg: What is on top should appear on the bottom and what is on the bottom should be on top) and there should be no flip left to right.

I've tried to flip it using ExifInterface.ORIENTATION_FLIP_VERTICAL, it works fine for onePlus device but not working with Samsung Galaxy s9 and thus out put image in gallery is oriented wrong.

Need help specifically for Samsung devices.

Xi Zhang (张熹)

unread,
Nov 1, 2021, 10:52:36 AM11/1/21
to Haider Saleem, Android CameraX Discussion Group
The saved image files already have an exif orientation, so if you overwrite it with ORIENTATION_FLIP_VERTICAL, unless the original value is ORIENTATION_NORMAL, the result would not be correct. To flip the image vertically, I would suggest using AndroidX' ExifInterface#flipVertically().

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/3dff1a6d-747b-460f-9a54-330517e1fbc1n%40android.com.
Message has been deleted

Haider Saleem

unread,
Nov 1, 2021, 12:32:25 PM11/1/21
to Android CameraX Discussion Group, Xi Zhang, Android CameraX Discussion Group
So it worked on Samsung device but within the app scope (displayed as vertically flipped in image view), didn't reflect in gallery and for onePlus device it didn't work altogether.

Xi Zhang (张熹)

unread,
Nov 1, 2021, 12:41:20 PM11/1/21
to Haider Saleem, Android CameraX Discussion Group
Could you share a code sample that uses the ExifInterface? Also could you attach the original image files?

Haider Saleem

unread,
Nov 1, 2021, 12:55:37 PM11/1/21
to Android CameraX Discussion Group, Xi Zhang, Android CameraX Discussion Group, Haider Saleem
Yeah, so here's code
 while saving image

val exif = ExifInterface(file!!.absolutePath)
exif.flipVertically()
exif.saveAttributes()

and for flipping live preview

matrix.postScale(scale, -1F, centerX, centerY)

First image shows the live preview and the second shows the image saved in gallery.
Screenshot_20211101-214512_Volk Tahoe.jpg                           Screenshot_20211101-214535_Gallery.jpg

Xi Zhang (张熹)

unread,
Nov 1, 2021, 1:08:24 PM11/1/21
to Haider Saleem, Android CameraX Discussion Group
Could you attach the original image files(instead of a screenshot) so I can check the exif values?

BTW, the gallery app might not handle the exif orientation correctly. Could you check if the orientation in the Google Photos app?

Haider Saleem

unread,
Nov 2, 2021, 2:52:07 AM11/2/21
to Android CameraX Discussion Group, Xi Zhang, Android CameraX Discussion Group
So I just checked with google photos in Samsung S9 and it was showing image as expected (Vertically flipped), and here's the image
I've checked exif orientation value for this image and it was exact that value which I assigned while saving it.

2021-11-01-21-45-19-055.jpg

Xi Zhang (张熹)

unread,
Nov 2, 2021, 9:15:11 AM11/2/21
to Haider Saleem, Android CameraX Discussion Group
So it's a bug in the Gallery app. In that case, there isn't much CameraX can do. You can choose to either ignore it, or flip the actual image bytes (which adds more latency).

Haider Saleem

unread,
Nov 2, 2021, 3:11:34 PM11/2/21
to Android CameraX Discussion Group, Xi Zhang, Android CameraX Discussion Group
I've tried flipping the bytes method but that's an expensive one and takes time, btw Thanks.
Reply all
Reply to author
Forward
0 new messages