fix rotating images by negative degrees

This commit is contained in:
tibbi 2019-02-07 11:31:31 +01:00
parent 77b4a65ac3
commit 076559aa9d

View file

@ -374,8 +374,13 @@ fun Activity.fixDateTaken(paths: ArrayList<String>, callback: (() -> Unit)? = nu
} }
fun BaseSimpleActivity.saveRotatedImageToFile(oldPath: String, newPath: String, degrees: Int, showToasts: Boolean, callback: () -> Unit) { 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 (oldPath == newPath && oldPath.isJpg()) {
if (tryRotateByExif(oldPath, degrees, showToasts, callback)) { if (tryRotateByExif(oldPath, newDegrees, showToasts, callback)) {
return return
} }
} }
@ -394,11 +399,11 @@ fun BaseSimpleActivity.saveRotatedImageToFile(oldPath: String, newPath: String,
val oldLastModified = File(oldPath).lastModified() val oldLastModified = File(oldPath).lastModified()
if (oldPath.isJpg()) { if (oldPath.isJpg()) {
copyFile(oldPath, tmpPath) copyFile(oldPath, tmpPath)
saveExifRotation(ExifInterface(tmpPath), degrees) saveExifRotation(ExifInterface(tmpPath), newDegrees)
} else { } else {
val inputstream = getFileInputStreamSync(oldPath) val inputstream = getFileInputStreamSync(oldPath)
val bitmap = BitmapFactory.decodeStream(inputstream) val bitmap = BitmapFactory.decodeStream(inputstream)
saveFile(tmpPath, bitmap, it as FileOutputStream, degrees) saveFile(tmpPath, bitmap, it as FileOutputStream, newDegrees)
} }
if (getDoesFilePathExist(newPath)) { if (getDoesFilePathExist(newPath)) {