improve exif orientation detecting from content uri images

This commit is contained in:
tibbi 2019-02-21 23:29:50 +01:00
parent 7e234d731a
commit 81abbe82ad

View file

@ -530,8 +530,16 @@ class PhotoFragment : ViewPagerFragment() {
try { try {
val path = mMedium.path val path = mMedium.path
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) val exif = android.media.ExifInterface(path)
orient = exif.getAttributeInt(android.media.ExifInterface.TAG_ORIENTATION, defaultOrientation) exif.getAttributeInt(android.media.ExifInterface.TAG_ORIENTATION, defaultOrientation)
}
if (orient == defaultOrientation || context!!.isPathOnOTG(mMedium.path)) { if (orient == defaultOrientation || context!!.isPathOnOTG(mMedium.path)) {
val uri = if (path.startsWith("content:/")) Uri.parse(path) else Uri.fromFile(File(path)) val uri = if (path.startsWith("content:/")) Uri.parse(path) else Uri.fromFile(File(path))