From 076559aa9d75c3a5384c2cd2b47383144682952b Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 7 Feb 2019 11:31:31 +0100 Subject: [PATCH] fix rotating images by negative degrees --- .../gallery/pro/extensions/Activity.kt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt index 3092f7c7e..487f45272 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Activity.kt @@ -374,8 +374,13 @@ fun Activity.fixDateTaken(paths: ArrayList, callback: (() -> Unit)? = nu } fun BaseSimpleActivity.saveRotatedImageToFile(oldPath: String, newPath: String, degrees: Int, showToasts: Boolean, callback: () -> Unit) { + var newDegrees = degrees + if (newDegrees < 0) { + newDegrees += 360 + } + if (oldPath == newPath && oldPath.isJpg()) { - if (tryRotateByExif(oldPath, degrees, showToasts, callback)) { + if (tryRotateByExif(oldPath, newDegrees, showToasts, callback)) { return } } @@ -394,11 +399,11 @@ fun BaseSimpleActivity.saveRotatedImageToFile(oldPath: String, newPath: String, val oldLastModified = File(oldPath).lastModified() if (oldPath.isJpg()) { copyFile(oldPath, tmpPath) - saveExifRotation(ExifInterface(tmpPath), degrees) + saveExifRotation(ExifInterface(tmpPath), newDegrees) } else { val inputstream = getFileInputStreamSync(oldPath) val bitmap = BitmapFactory.decodeStream(inputstream) - saveFile(tmpPath, bitmap, it as FileOutputStream, degrees) + saveFile(tmpPath, bitmap, it as FileOutputStream, newDegrees) } if (getDoesFilePathExist(newPath)) {