From 72aa5c61b6f49ed4d9a69994ba08cdc5a1bfb5e5 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Thu, 14 Mar 2013 17:18:20 -0700 Subject: [PATCH] Adjusted how large bitmaps are scaled to keep bigger images around --- api/src/com/todoroo/andlib/utility/AndroidUtilities.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/api/src/com/todoroo/andlib/utility/AndroidUtilities.java b/api/src/com/todoroo/andlib/utility/AndroidUtilities.java index 058f773ac..be12264f1 100644 --- a/api/src/com/todoroo/andlib/utility/AndroidUtilities.java +++ b/api/src/com/todoroo/andlib/utility/AndroidUtilities.java @@ -122,18 +122,19 @@ public class AndroidUtilities { /** Read a bitmap from the specified file, scaling if necessary * Returns null if scaling failed after several tries */ + private static final int[] SAMPLE_SIZES = { 1, 2, 4, 6, 8, 10 }; public static Bitmap readScaledBitmap(String file) { Bitmap bitmap = null; - int tries = 1; + int tries = 0; BitmapFactory.Options opts = new BitmapFactory.Options(); - while(bitmap == null && tries < 32) { - opts.inSampleSize = tries; + while(bitmap == null && tries < SAMPLE_SIZES.length) { + opts.inSampleSize = SAMPLE_SIZES[tries]; try { bitmap = BitmapFactory.decodeFile(file, opts); } catch (OutOfMemoryError e) { // Too big } - tries = tries * 2; + tries++; } return bitmap;