error catch for saving image

This commit is contained in:
rebelonion 2024-01-14 01:45:46 -06:00
parent e7631e021e
commit 063d314c36

View file

@ -625,13 +625,16 @@ fun shareImage(title: String, bitmap: Bitmap, context: Context) {
fun saveImage(image: Bitmap, path: String, imageFileName: String): File? { fun saveImage(image: Bitmap, path: String, imageFileName: String): File? {
val imageFile = File(path, "$imageFileName.png") val imageFile = File(path, "$imageFileName.png")
return tryWith { return try {
val fOut: OutputStream = FileOutputStream(imageFile) val fOut: OutputStream = FileOutputStream(imageFile)
image.compress(Bitmap.CompressFormat.PNG, 0, fOut) image.compress(Bitmap.CompressFormat.PNG, 0, fOut)
fOut.close() fOut.close()
scanFile(imageFile.absolutePath, currContext()!!) scanFile(imageFile.absolutePath, currContext()!!)
toast(String.format(currContext()!!.getString(R.string.saved_to_path, path))) toast(String.format(currContext()!!.getString(R.string.saved_to_path, path)))
imageFile imageFile
} catch (e: Exception) {
snackString("Failed to save image: ${e.localizedMessage}")
null
} }
} }