error catch for saving image
This commit is contained in:
parent
e7631e021e
commit
063d314c36
1 changed files with 4 additions and 1 deletions
|
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue