From ad5d192fb1cfb124ed3cf86c71c4a2e8226b1d1e Mon Sep 17 00:00:00 2001 From: Agnieszka C <85929121+Aga-C@users.noreply.github.com> Date: Mon, 3 Jul 2023 19:02:38 +0200 Subject: [PATCH] Fixed exception on image resizing (#2883) --- .../pro/dialogs/ResizeMultipleImagesDialog.kt | 2 +- .../gallery/pro/extensions/Activity.kt | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ResizeMultipleImagesDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ResizeMultipleImagesDialog.kt index 6066accde..2ace69d41 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ResizeMultipleImagesDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/dialogs/ResizeMultipleImagesDialog.kt @@ -87,7 +87,7 @@ class ResizeMultipleImagesDialog( val lastModified = File(path).lastModified() try { - resizeImage(path, size) { + resizeImage(path, path, size) { if (it) { pathsToRescan.add(path) pathLastModifiedMap[path] = lastModified 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 c6519fcbc..3abaa9132 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 @@ -799,7 +799,7 @@ fun BaseSimpleActivity.launchResizeImageDialog(path: String, callback: (() -> Un val file = File(newPath) val pathLastModifiedMap = mapOf(file.absolutePath to file.lastModified()) try { - resizeImage(newPath, newSize) { success -> + resizeImage(path, newPath, newSize) { success -> if (success) { toast(R.string.file_saved) @@ -822,17 +822,17 @@ fun BaseSimpleActivity.launchResizeImageDialog(path: String, callback: (() -> Un } } -fun BaseSimpleActivity.resizeImage(path: String, size: Point, callback: (success: Boolean) -> Unit) { +fun BaseSimpleActivity.resizeImage(oldPath: String, newPath: String, size: Point, callback: (success: Boolean) -> Unit) { var oldExif: ExifInterface? = null if (isNougatPlus()) { - val inputStream = contentResolver.openInputStream(Uri.fromFile(File(path))) + val inputStream = contentResolver.openInputStream(Uri.fromFile(File(oldPath))) oldExif = ExifInterface(inputStream!!) } - val newBitmap = Glide.with(applicationContext).asBitmap().load(path).submit(size.x, size.y).get() + val newBitmap = Glide.with(applicationContext).asBitmap().load(oldPath).submit(size.x, size.y).get() - val newFile = File(path) - val newFileDirItem = FileDirItem(path, path.getFilenameFromPath()) + val newFile = File(newPath) + val newFileDirItem = FileDirItem(newPath, newPath.getFilenameFromPath()) getFileOutputStream(newFileDirItem, true) { out -> if (out != null) { out.use {