subsampling-scale-image-view
subsampling-scale-image-view copied to clipboard
Wrong Orientation for some images
Expected behaviour Correct image with correct orientation
Actual behaviour Showing image with the wrong orientation. Some rotated to 360 degrees while some rotated to 90 degrees.
Affected devices All of it
Affected images some rotated images from the camera. The image resides in a folder.
tried the following code but no use
imageView.orientation = SubsamplingScaleImageView.ORIENTATION_USE_EXIF imageView.setImage(ImageSource.uri(FileProvider.getUriForFile (this.context!!, "com.app.appname.FileProvider", File(path))))
On my app it's the same. It can be reproduced using the following git repo: https://github.com/SailReal/ssiv-kotlin-sample its a fork of the demo app and added in a quiet hacky way, that the images can be loaded from a separate folder (https://github.com/SailReal/ssiv-kotlin-sample/commit/2609ffb815f8dde43beefe677b73b418f095afc7). Furthermore I added imageView.orientation = SubsamplingScaleImageView.ORIENTATION_USE_EXIF
If you copy the folder from https://github.com/ianare/exif-samples/tree/master/jpg/orientation in a empty folder, choose the folder when selecting "View pager galliers" the images aren't displayed correctly.

The original report suggested it was EXIF rotation that was an issue, and this sample app appears to be illustrating a problem only with the flip H/V orientations. SSIV does not support flipped images, and I don't intend to add this support because it's a very rare use case.
I ran into this problem.
I have an image that can reproduce this, but I can't share it publicly as it contains sensitive info but I would be happy to send it to you @davemorrissey by e-mail if you desire.
It was a photo downloaded from the Internet opened using Intent.ACTION_OPEN_DOCUMENT from the Downloads documents provider (a content:// URI). It had the same problem on the original phone though, the MediaStore would return orientation of 0 although the EXIF data shows 90.
I fixed it on my hand by using ExifInterface all the time, even for the content: URIs using the ExifInterface(FileDescriptor fileDescriptor) constructor and context.contentResolver.openFileDescriptor().
So far so good, I'm not sure if there are any counter-indications of using ExifInterface for every Uri scheme.
Here's a workaround using ExifInterface and some good old Android View flippings to get around this issue. There's surely better ways to go about it but it's a good starting point.
private fun SubsamplingScaleImageView.setExifOrientation(file: File) {
val exifOrientation = ExifInterface(file).getAttributeInt(ExifInterface.TAG_ORIENTATION, 1)
orientation = when (exifOrientation) {
ExifInterface.ORIENTATION_FLIP_HORIZONTAL -> {
scaleX = -1f
SubsamplingScaleImageView.ORIENTATION_0
}
ExifInterface.ORIENTATION_FLIP_VERTICAL -> {
scaleY = -1f
SubsamplingScaleImageView.ORIENTATION_0
}
ExifInterface.ORIENTATION_TRANSVERSE -> {
scaleX = -1f
SubsamplingScaleImageView.ORIENTATION_270
}
ExifInterface.ORIENTATION_TRANSPOSE -> {
scaleX = -1f
SubsamplingScaleImageView.ORIENTATION_90
}
else -> SubsamplingScaleImageView.ORIENTATION_USE_EXIF
}
}