|
|
@ -122,18 +122,19 @@ public class AndroidUtilities {
|
|
|
|
|
|
|
|
|
|
|
|
/** Read a bitmap from the specified file, scaling if necessary
|
|
|
|
/** Read a bitmap from the specified file, scaling if necessary
|
|
|
|
* Returns null if scaling failed after several tries */
|
|
|
|
* 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) {
|
|
|
|
public static Bitmap readScaledBitmap(String file) {
|
|
|
|
Bitmap bitmap = null;
|
|
|
|
Bitmap bitmap = null;
|
|
|
|
int tries = 1;
|
|
|
|
int tries = 0;
|
|
|
|
BitmapFactory.Options opts = new BitmapFactory.Options();
|
|
|
|
BitmapFactory.Options opts = new BitmapFactory.Options();
|
|
|
|
while(bitmap == null && tries < 32) {
|
|
|
|
while(bitmap == null && tries < SAMPLE_SIZES.length) {
|
|
|
|
opts.inSampleSize = tries;
|
|
|
|
opts.inSampleSize = SAMPLE_SIZES[tries];
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
bitmap = BitmapFactory.decodeFile(file, opts);
|
|
|
|
bitmap = BitmapFactory.decodeFile(file, opts);
|
|
|
|
} catch (OutOfMemoryError e) {
|
|
|
|
} catch (OutOfMemoryError e) {
|
|
|
|
// Too big
|
|
|
|
// Too big
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tries = tries * 2;
|
|
|
|
tries++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return bitmap;
|
|
|
|
return bitmap;
|
|
|
|