Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to make BitmapFactory.decodeFile() respect EXIF?

In my tests, a Bitmap created by BitmapFactory.decodeFile() doesn't respect EXIF header.

For example, with portrait images taken by a devices that doesn't rotate actual pixel data depending on camera orientation but rather stores it in EXIF header, when I'm calling Bitmap.getWidth() and Bitmap.getHeight(), they return incorrect values (height for width and vice versa).

Is there a way to make BitmapFactory.decodeFile() respect EXIF and produce a correct Bitmap?

If not, what is the recommended pattern to handle this issue?

Without an advice from experienced Android devs, the only way I see is to pre-process taken images (load, rotate according to EXIF, and save). But apart from the huge processing overhead, this might cause OutOfMemoryExceptions for large camera resolutions (in cases when you can't reduce the quality by using BitmapFactory.Options.inSampleSize to load downscaled images).

like image 963
Alexander Abakumov Avatar asked Oct 26 '25 03:10

Alexander Abakumov


1 Answers

You can do this with Glide now. See the "Background Threads" section here:

https://bumptech.github.io/glide/doc/getting-started.html

Bitmap bitmap = Glide.with(context).asBitmap().load(new File(fileName)).skipMemoryCache(true).submit().get();

Glide takes into consideration EXIF. You'll need to load it on a background thread. I was using Glide 4.9.0

like image 192
metaphyze Avatar answered Oct 28 '25 16:10

metaphyze



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!