@@ -75,7 +75,7 @@ class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId
7575 else -> 0
7676 }
7777
78- image = rotate(image, imageRot + deviceRot + previewRot)
78+ image = rotate(image, imageRot + deviceRot + previewRot) ? : return " "
7979 image.compress(Bitmap .CompressFormat .JPEG , 80 , fos)
8080 fos?.close()
8181 return photoFile.absolutePath
@@ -92,13 +92,21 @@ class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId
9292 return " "
9393 }
9494
95- private fun rotate (bitmap : Bitmap , degree : Int ): Bitmap {
95+ private fun rotate (bitmap : Bitmap , degree : Int ): Bitmap ? {
9696 val width = bitmap.width
9797 val height = bitmap.height
9898
9999 val matrix = Matrix ()
100100 matrix.setRotate((degree % 360 ).toFloat())
101- return Bitmap .createBitmap(bitmap, 0 , 0 , width, height, matrix, true )
101+ try {
102+ return Bitmap .createBitmap(bitmap, 0 , 0 , width, height, matrix, true )
103+ } catch (e: OutOfMemoryError ) {
104+ Log .e(TAG , " PhotoProcessor rotate OutOfMemoryError $e " )
105+ activity.runOnUiThread {
106+ activity.toast(R .string.photo_not_saved)
107+ }
108+ }
109+ return null
102110 }
103111
104112 override fun onPostExecute (path : String ) {
0 commit comments