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

But sadly that is not implemented in this library.
To Reproduce
Steps to reproduce the behavior:
- Open the app
- Select
SAMPLE USING CROPIMAGEVIEW
- 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

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) |
Describe the bug

EXIF values not only define rotation but also mirroring, see EXIF values 2, 4, 5, 7:
But sadly that is not implemented in this library.
To Reproduce
Steps to reproduce the behavior:
SAMPLE USING CROPIMAGEVIEWThe 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
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
Android-Image-Cropper/cropper/src/main/java/com/canhub/cropper/BitmapUtils.kt
Lines 90 to 107 in 2f867e9