Skip to content

[BUG] - Not all EXIF values are supported #408

Description

@Mouwrice
  • Lib Version 4.3.0

Describe the bug
EXIF values not only define rotation but also mirroring, see EXIF values 2, 4, 5, 7:
image

But sadly that is not implemented in this library.

To Reproduce
Steps to reproduce the behavior:

  1. Open the app
  2. Select SAMPLE USING CROPIMAGEVIEW
  3. Choose an image that has EXIF value 2, 4, 5 or 7 (using the bottom left button) and see that they are orientated wrongly.

The exact images used are:
https://github.com/recurser/exif-orientation-examples/blob/master/Landscape_2.jpg
https://github.com/recurser/exif-orientation-examples/blob/master/Landscape_4.jpg
https://github.com/recurser/exif-orientation-examples/blob/master/Landscape_5.jpg
https://github.com/recurser/exif-orientation-examples/blob/master/Landscape_7.jpg

Try to crop an image that has an EXIF value of 2, 4, 5 or 7 and see that the image is in fact not correctly mirrored:
This is an image with EXIF value of 2
image

Expected behavior
Make use of these enums:
https://developer.android.com/reference/androidx/exifinterface/media/ExifInterface#ORIENTATION_FLIP_HORIZONTAL
https://developer.android.com/reference/androidx/exifinterface/media/ExifInterface#ORIENTATION_FLIP_VERTICAL
https://developer.android.com/reference/androidx/exifinterface/media/ExifInterface#ORIENTATION_TRANSPOSE
https://developer.android.com/reference/androidx/exifinterface/media/ExifInterface#ORIENTATION_TRANSVERSE

Which define what tranformations you need to apply to the image to get the correct orientation.

Media
You can test this out yourself by using the images provided in this repo:
https://github.com/recurser/exif-orientation-examples

Proposed solution
From a quick overview it seems that you should be able to pretty easily update the rotate function by exif value to also flip the image

/**
* Rotate the given image by given Exif value.<br></br>
* If no rotation is required the image will not be rotated.<br></br>
* New bitmap is created and the old one is recycled.
*/
fun rotateBitmapByExif(bitmap: Bitmap?, exif: ExifInterface): RotateBitmapResult {
val degrees: Int = when (
exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL
)
) {
ExifInterface.ORIENTATION_ROTATE_90 -> 90
ExifInterface.ORIENTATION_ROTATE_180 -> 180
ExifInterface.ORIENTATION_ROTATE_270 -> 270
else -> 0
}
return RotateBitmapResult(bitmap, degrees)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions