diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt index dd0ccb737..2e8b5a2ce 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/fragments/PhotoFragment.kt @@ -33,6 +33,7 @@ import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.getFileSignature import com.simplemobiletools.gallery.extensions.getRealPathFromURI import com.simplemobiletools.gallery.extensions.portrait +import com.simplemobiletools.gallery.helpers.GlideDecoder import com.simplemobiletools.gallery.helpers.GlideRotateTransformation import com.simplemobiletools.gallery.helpers.MEDIUM import com.simplemobiletools.gallery.models.Medium @@ -199,6 +200,7 @@ class PhotoFragment : ViewPagerFragment() { private fun addZoomableView() { if ((medium.isImage()) && isFragmentVisible && view.subsampling_view.visibility == View.GONE) { view.subsampling_view.apply { + setBitmapDecoderClass(GlideDecoder::class.java) maxScale = 10f beVisible() setImage(ImageSource.uri(medium.path)) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/GlideDecoder.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/GlideDecoder.kt index 1e3796359..9cba5dbef 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/GlideDecoder.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/GlideDecoder.kt @@ -5,6 +5,7 @@ import android.graphics.Bitmap import android.graphics.Canvas import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable +import android.media.ExifInterface import android.net.Uri import com.bumptech.glide.Glide import com.bumptech.glide.load.DecodeFormat @@ -14,9 +15,13 @@ import com.davemorrissey.labs.subscaleview.decoder.ImageDecoder class GlideDecoder : ImageDecoder { override fun decode(context: Context, uri: Uri): Bitmap { + val exif = android.media.ExifInterface(uri.path) + val orientation = exif.getAttributeInt(android.media.ExifInterface.TAG_ORIENTATION, android.media.ExifInterface.ORIENTATION_NORMAL) + val options = RequestOptions() .format(DecodeFormat.PREFER_ARGB_8888) .diskCacheStrategy(DiskCacheStrategy.NONE) + .transform(GlideRotateTransformation(context, getRotationDegrees(orientation))) val drawable = Glide.with(context) .load(uri) @@ -45,4 +50,12 @@ class GlideDecoder : ImageDecoder { drawable.draw(canvas) return bitmap } + + // rotating backwards intentionally, as SubsamplingScaleImageView will rotate it properly at displaying + private fun getRotationDegrees(orientation: Int) = when (orientation) { + ExifInterface.ORIENTATION_ROTATE_270 -> 90f + ExifInterface.ORIENTATION_ROTATE_180 -> 180f + ExifInterface.ORIENTATION_ROTATE_90 -> 270f + else -> 0f + } }