fix rotating images by negative degrees

This commit is contained in:
tibbi 2019-02-07 11:31:31 +01:00
parent 77b4a65ac3
commit 076559aa9d
1 changed files with 8 additions and 3 deletions

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) {
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)) {