From 40de93100c2b7640805ca01bfc5c4f547ef91acd Mon Sep 17 00:00:00 2001 From: tibbi Date: Tue, 3 Jul 2018 23:21:35 +0200 Subject: [PATCH] try scaling down the panorama image, if it keeps running out of memory --- .../gallery/activities/PanoramaActivity.kt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PanoramaActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PanoramaActivity.kt index f88c7c960..8587ec957 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PanoramaActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/PanoramaActivity.kt @@ -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 }