From a10fd3e8768c0259a1f8edb393f5d193258903e5 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 8 Feb 2018 21:11:22 +0100 Subject: [PATCH] fix #643, properly handle saving edited images with file uri --- .../gallery/activities/EditActivity.kt | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt index 8e3d4d6c4..c1408b2c9 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/EditActivity.kt @@ -144,24 +144,28 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener override fun onCropImageComplete(view: CropImageView, result: CropImageView.CropResult) { if (result.error == null) { if (isCropIntent) { - var inputStream: InputStream? = null - var outputStream: OutputStream? = null - try { - val stream = ByteArrayOutputStream() - result.bitmap.compress(CompressFormat.JPEG, 100, stream) - inputStream = ByteArrayInputStream(stream.toByteArray()) - outputStream = contentResolver.openOutputStream(saveUri) - inputStream.copyTo(outputStream) - } finally { - inputStream?.close() - outputStream?.close() - } + if (saveUri.scheme == "file") { + saveBitmapToFile(result.bitmap, saveUri.path) + } else { + var inputStream: InputStream? = null + var outputStream: OutputStream? = null + try { + val stream = ByteArrayOutputStream() + result.bitmap.compress(CompressFormat.JPEG, 100, stream) + inputStream = ByteArrayInputStream(stream.toByteArray()) + outputStream = contentResolver.openOutputStream(saveUri) + inputStream.copyTo(outputStream) + } finally { + inputStream?.close() + outputStream?.close() + } - Intent().apply { - addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - setResult(RESULT_OK, this) + Intent().apply { + addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + setResult(RESULT_OK, this) + } + finish() } - finish() } else if (saveUri.scheme == "file") { SaveAsDialog(this, saveUri.path, true) { saveBitmapToFile(result.bitmap, it)