mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 22:47:59 +01:00
rotate SD card files by exif when possible
This commit is contained in:
parent
ac08320bc4
commit
5a4a35f6d2
1 changed files with 24 additions and 7 deletions
|
@ -2,6 +2,7 @@ package com.simplemobiletools.gallery.activities
|
||||||
|
|
||||||
import android.animation.Animator
|
import android.animation.Animator
|
||||||
import android.animation.ValueAnimator
|
import android.animation.ValueAnimator
|
||||||
|
import android.annotation.TargetApi
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.pm.ActivityInfo
|
import android.content.pm.ActivityInfo
|
||||||
|
@ -521,15 +522,32 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TargetApi(Build.VERSION_CODES.N)
|
||||||
private fun saveImageToFile(oldPath: String, newPath: String) {
|
private fun saveImageToFile(oldPath: String, newPath: String) {
|
||||||
toast(R.string.saving)
|
toast(R.string.saving)
|
||||||
if (oldPath == newPath && oldPath.isJpg() && !isPathOnSD(oldPath)) {
|
if (oldPath == newPath && oldPath.isJpg()) {
|
||||||
try {
|
try {
|
||||||
saveRotation(oldPath)
|
if (!isPathOnSD(oldPath)) {
|
||||||
|
saveExifRotation(ExifInterface(oldPath))
|
||||||
|
mRotationDegrees = 0f
|
||||||
|
invalidateOptionsMenu()
|
||||||
toast(R.string.file_saved)
|
toast(R.string.file_saved)
|
||||||
return
|
return
|
||||||
|
} else if (isNougatPlus()) {
|
||||||
|
val documentFile = getSomeDocumentFile(oldPath)
|
||||||
|
if (documentFile != null) {
|
||||||
|
val parcelFileDescriptor = contentResolver.openFileDescriptor(documentFile.uri, "rw")
|
||||||
|
val fileDescriptor = parcelFileDescriptor.fileDescriptor
|
||||||
|
saveExifRotation(ExifInterface(fileDescriptor))
|
||||||
|
mRotationDegrees = 0f
|
||||||
|
invalidateOptionsMenu()
|
||||||
|
toast(R.string.file_saved)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
showErrorToast(e)
|
showErrorToast(e)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -547,7 +565,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
val oldLastModified = getCurrentFile().lastModified()
|
val oldLastModified = getCurrentFile().lastModified()
|
||||||
if (oldPath.isJpg()) {
|
if (oldPath.isJpg()) {
|
||||||
copyFile(getCurrentFile(), tmpFile)
|
copyFile(getCurrentFile(), tmpFile)
|
||||||
saveRotation(tmpFile.absolutePath)
|
saveExifRotation(ExifInterface(tmpFile.absolutePath))
|
||||||
} else {
|
} else {
|
||||||
saveFile(tmpFile, bitmap, it as FileOutputStream)
|
saveFile(tmpFile, bitmap, it as FileOutputStream)
|
||||||
}
|
}
|
||||||
|
@ -606,8 +624,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
||||||
bmp.compress(file.absolutePath.getCompressionFormat(), 90, out)
|
bmp.compress(file.absolutePath.getCompressionFormat(), 90, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun saveRotation(destinationPath: String) {
|
private fun saveExifRotation(exif: ExifInterface) {
|
||||||
val exif = ExifInterface(destinationPath)
|
|
||||||
val orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)
|
val orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)
|
||||||
val orientationDegrees = (degreesForRotation(orientation) + mRotationDegrees) % 360
|
val orientationDegrees = (degreesForRotation(orientation) + mRotationDegrees) % 360
|
||||||
exif.setAttribute(ExifInterface.TAG_ORIENTATION, rotationFromDegrees(orientationDegrees))
|
exif.setAttribute(ExifInterface.TAG_ORIENTATION, rotationFromDegrees(orientationDegrees))
|
||||||
|
|
Loading…
Reference in a new issue