My app takes photos, performs some processing, and ensures they are included in the Android gallery.
The problem I have is that when I open the images in the gallery they aren't rotated correctly - although examining the Exif data shows that the orientation tag is set and appears to be correct. If I load it into an Exif examination tool it will say something like "Orientation: Rotate 90 CW" but I notice that other applications, such as Gimp, also appear to miss the Exif data so I am wondering whether there is something wrong with the data as I am storing it.
My Exif orientation code is written like this:
private void writeOrientation(int orientation, String path) {
try {
int exifOrientation = ExifInterface.ORIENTATION_NORMAL;
if (45 < orientation) {
if (orientation <= 135) {
exifOrientation = ExifInterface.ORIENTATION_ROTATE_90;
} else if (orientation <= 225) {
exifOrientation = ExifInterface.ORIENTATION_ROTATE_180;
} else {
exifOrientation = ExifInterface.ORIENTATION_ROTATE_270;
}
}
ExifInterface exif = new ExifInterface(path);
exif.setAttribute(ExifInterface.TAG_ORIENTATION, String.valueOf(exifOrientation));
exif.saveAttributes();
} catch (Exception e) {
Log.w(TAG, "Failing to write orientation: " + e.getMessage());
Log.getStackTraceString(e);
}
}
This does appear to be working- in my own code I'm rotating the image according to its orientation and it looks normal. But in the gallery, all my portrait images are still showing as landscape.
Does the gallery use the Exif data to rotate images? If not is there something else that it does use or should I just be overwriting the image with the rotated version? How can I make sure that the gallery and other apps that my images are loaded into have everything the need to display them in the correct orientation?