From 063d314c36a07e010cd497c34f578021eec0fbd8 Mon Sep 17 00:00:00 2001 From: rebelonion <87634197+rebelonion@users.noreply.github.com> Date: Sun, 14 Jan 2024 01:45:46 -0600 Subject: [PATCH] error catch for saving image --- app/src/main/java/ani/dantotsu/Functions.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/ani/dantotsu/Functions.kt b/app/src/main/java/ani/dantotsu/Functions.kt index a1035d05..603a766e 100644 --- a/app/src/main/java/ani/dantotsu/Functions.kt +++ b/app/src/main/java/ani/dantotsu/Functions.kt @@ -625,13 +625,16 @@ fun shareImage(title: String, bitmap: Bitmap, context: Context) { fun saveImage(image: Bitmap, path: String, imageFileName: String): File? { val imageFile = File(path, "$imageFileName.png") - return tryWith { + return try { val fOut: OutputStream = FileOutputStream(imageFile) image.compress(Bitmap.CompressFormat.PNG, 0, fOut) fOut.close() scanFile(imageFile.absolutePath, currContext()!!) toast(String.format(currContext()!!.getString(R.string.saved_to_path, path))) imageFile + } catch (e: Exception) { + snackString("Failed to save image: ${e.localizedMessage}") + null } }