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 OutOfMemoryException
s for large camera resolutions (in cases when you can't reduce the quality by using BitmapFactory.Options.inSampleSize
to load downscaled images).
Is there a way to make BitmapFactory.decodeFile() respect EXIF and produce a correct Bitmap?
No, sorry.
what is the recommended pattern to handle this issue?
Use the support library's ExifInterface
to determine the desired orientation. Then, depending upon your use of the Bitmap
, either rotate the view (e.g., ImageView
) or rotate the Bitmap
. This sample project illustrates both approaches, though I use a separate set of EXIF code, as some things that I use in that sample are not supported by the support library's ExifInterface
.