Its a known bug, its not because of large files.
Bitmap is stored in native heap, but it will get garbage collected
automatically, calling recycle() or by other process by making
weakreference or softreference To fix OutOfMemory you should do
something like this:
options.inSampleSize = calculateInSampleSize(options,bitmapWidth,bitmapHeight);
public static int calculateInSampleSize(
BitmapFactory.Options options, int reqWidth, int reqHeight) {
final int height = options.outHeight;
final int width = options.outWidth;
int inSampleSize = 1;
if (height > reqHeight || width > reqWidth) {
final int halfHeight = height / 2;
final int halfWidth = width / 2;
// Calculate the largest inSampleSize value that is a power of 2 and keeps both
// height and width larger than the requested height and width.
while ((halfHeight / inSampleSize) > reqHeight
&& (halfWidth / inSampleSize) > reqWidth) {
inSampleSize *= 2;
}
}
return inSampleSize;
}
For example, an image with resolution 2048x1536 that is decoded with
an inSampleSize of 4 produces a bitmap of approximately 512x384
|