catch out of memory error thrown at rotating images before save
This commit is contained in:
parent
e77f211f07
commit
1c60320f5c
|
@ -32,7 +32,7 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile 'com.simplemobiletools:commons:2.21.11'
|
compile 'com.simplemobiletools:commons:2.21.12'
|
||||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId
|
||||||
else -> 0
|
else -> 0
|
||||||
}
|
}
|
||||||
|
|
||||||
image = rotate(image, imageRot + deviceRot + previewRot)
|
image = rotate(image, imageRot + deviceRot + previewRot) ?: return ""
|
||||||
image.compress(Bitmap.CompressFormat.JPEG, 80, fos)
|
image.compress(Bitmap.CompressFormat.JPEG, 80, fos)
|
||||||
fos?.close()
|
fos?.close()
|
||||||
return photoFile.absolutePath
|
return photoFile.absolutePath
|
||||||
|
@ -92,13 +92,21 @@ class PhotoProcessor(val activity: MainActivity, val uri: Uri?, val currCameraId
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun rotate(bitmap: Bitmap, degree: Int): Bitmap {
|
private fun rotate(bitmap: Bitmap, degree: Int): Bitmap? {
|
||||||
val width = bitmap.width
|
val width = bitmap.width
|
||||||
val height = bitmap.height
|
val height = bitmap.height
|
||||||
|
|
||||||
val matrix = Matrix()
|
val matrix = Matrix()
|
||||||
matrix.setRotate((degree % 360).toFloat())
|
matrix.setRotate((degree % 360).toFloat())
|
||||||
|
try {
|
||||||
return Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true)
|
return Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true)
|
||||||
|
} catch (e: OutOfMemoryError) {
|
||||||
|
Log.e(TAG, "PhotoProcessor rotate OutOfMemoryError $e")
|
||||||
|
activity.runOnUiThread {
|
||||||
|
activity.toast(R.string.photo_not_saved)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPostExecute(path: String) {
|
override fun onPostExecute(path: String) {
|
||||||
|
|
Loading…
Reference in New Issue