try scaling down the panorama image, if it keeps running out of memory

This commit is contained in:
tibbi 2018-07-03 23:21:35 +02:00
parent c32b332804
commit 40de93100c
1 changed files with 14 additions and 2 deletions

View File

@ -129,8 +129,20 @@ open class PanoramaActivity : SimpleActivity() {
setupButtonMargins()
}
private fun getBitmapToLoad(path: String): Bitmap {
val bitmap = BitmapFactory.decodeFile(path)
private fun getBitmapToLoad(path: String): Bitmap? {
val options = BitmapFactory.Options()
options.inSampleSize = 1
var bitmap: Bitmap? = null
for (i in 0..10) {
try {
bitmap = BitmapFactory.decodeFile(path, options)
break
} catch (e: OutOfMemoryError) {
options.inSampleSize *= 2
}
}
return bitmap
}