Bitmaps
always stored in the device Heap Memory , and your device heap memory can't afford that number of Bitmaps
as may be the way you try works on the same resolution of the image, So, at first try to grow the heap using your app manifest, then try this way to resize your Bitmaps
:
public static Bitmap scaleBitmap(Bitmap bitmapToScale, float newWidth, float newHeight) {
if(bitmapToScale == null)
return null;
//get the original width and height
int width = bitmapToScale.getWidth();
int height = bitmapToScale.getHeight();
// create a matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(newWidth / width, newHeight / height);
// recreate the new Bitmap and set it back
return Bitmap.createBitmap(bitmapToScale, 0, 0, bitmapToScale.getWidth(), bitmapToScale.getHeight(), matrix, true);
}
if this don't work either, so, you have to make one of the following:
- assign to each image a much less width and height.
- compress the image using something like ImageLoader.
- use another device with much Heap Space.
- limit the number of images used.
HINT: recycling the Bitmap totally removes it from the Heap memory, So, it's logical to have a "cannot draw recycled bitmaps"
error, So, if you want to recycle
it and then use it in your app, you have to store it at first in something like ArrayList<Bitmaps>
.