From fa4971f50c5b36576ba75ea651c487a81fdf8f0a Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Thu, 14 Mar 2013 18:05:56 -0700 Subject: [PATCH] More improvements to how bitmap scaling is handled --- api/src/com/todoroo/andlib/utility/AndroidUtilities.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/api/src/com/todoroo/andlib/utility/AndroidUtilities.java b/api/src/com/todoroo/andlib/utility/AndroidUtilities.java index be12264f1..63b6910a4 100644 --- a/api/src/com/todoroo/andlib/utility/AndroidUtilities.java +++ b/api/src/com/todoroo/andlib/utility/AndroidUtilities.java @@ -123,11 +123,12 @@ 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 }; + private static final int MAX_DIM = 1024; public static Bitmap readScaledBitmap(String file) { Bitmap bitmap = null; int tries = 0; BitmapFactory.Options opts = new BitmapFactory.Options(); - while(bitmap == null && tries < SAMPLE_SIZES.length) { + while(bitmap == null || ((bitmap.getWidth() > MAX_DIM || bitmap.getHeight() > MAX_DIM) && tries < SAMPLE_SIZES.length)) { opts.inSampleSize = SAMPLE_SIZES[tries]; try { bitmap = BitmapFactory.decodeFile(file, opts);