From 81abbe82ad84294bc0eae41dddd7b0d2a1bc4faa Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 21 Feb 2019 23:29:50 +0100 Subject: [PATCH] improve exif orientation detecting from content uri images --- .../gallery/pro/fragments/PhotoFragment.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt index cc64782cd..4a4754c94 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/fragments/PhotoFragment.kt @@ -530,8 +530,16 @@ class PhotoFragment : ViewPagerFragment() { try { val path = mMedium.path - val exif = android.media.ExifInterface(path) - orient = exif.getAttributeInt(android.media.ExifInterface.TAG_ORIENTATION, defaultOrientation) + orient = if (path.startsWith("content:/")) { + val inputStream = context!!.contentResolver.openInputStream(Uri.parse(path)) + val exif = ExifInterface() + exif.readExif(inputStream, ExifInterface.Options.OPTION_ALL) + val tag = exif.getTag(ExifInterface.TAG_ORIENTATION) + tag?.getValueAsInt(defaultOrientation) ?: defaultOrientation + } else { + val exif = android.media.ExifInterface(path) + exif.getAttributeInt(android.media.ExifInterface.TAG_ORIENTATION, defaultOrientation) + } if (orient == defaultOrientation || context!!.isPathOnOTG(mMedium.path)) { val uri = if (path.startsWith("content:/")) Uri.parse(path) else Uri.fromFile(File(path))