catch OutOfMemory errors at saving images

This commit is contained in:
tibbi 2018-01-23 16:48:30 +01:00
parent 95e75b4e74
commit 16d6d2044d
1 changed files with 8 additions and 2 deletions

View File

@ -83,7 +83,11 @@ class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId
} else { } else {
matrix.preScale(-1f, 1f) matrix.preScale(-1f, 1f)
} }
image = Bitmap.createBitmap(image, 0, 0, image.width, image.height, matrix, false) try {
image = Bitmap.createBitmap(image, 0, 0, image.width, image.height, matrix, false)
} catch (e: OutOfMemoryError) {
activity.toast(R.string.out_of_memory_error)
}
} }
image.compress(Bitmap.CompressFormat.JPEG, activity.config.photoQuality, fos) image.compress(Bitmap.CompressFormat.JPEG, activity.config.photoQuality, fos)
@ -140,7 +144,9 @@ class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId
override fun onPostExecute(path: String) { override fun onPostExecute(path: String) {
super.onPostExecute(path) super.onPostExecute(path)
activity.mediaSaved(path) if (path.isNotEmpty()) {
activity.mediaSaved(path)
}
} }
interface MediaSavedListener { interface MediaSavedListener {