Out of memory with allocation of 9830416 bytes with bitmap

I get the image from my resources folder and I have this exception:

03-11 10:18:28.019: E/dalvikvm-heap(4052): Out of memory on a 9830416-byte allocation.

I have this error here:

//stream to get photo
InputStream bitmap=null;                        
bitmap=getResources().getAssets().open("ProduitsMini/"+productList.get(rang).getImg_mini());
Bitmap bit=BitmapFactory.decodeStream(bitmap);

// get drawable image
Drawable mDrawable = new BitmapDrawable(getResources(),bit);

This is strange because I do not have this error on every device, but only with the Galaxy S3.

+5
source share
1 answer

You can try adding below code

InputStream bitmap=null; 
bitmap=getResources().getAssets().open("ProduitsMini/"+productList.get(rang).getImg_mini());

BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 8;
Bitmap preview_bitmap = BitmapFactory.decodeStream(bitmap,null,options);

This inSampleSize parameter reduces memory consumption.

You can link to the link below

fooobar.com/questions/11000 / ...

+9
source

All Articles