Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OutOfMemoryError: bitmap size exceeds VM budget :- Android [duplicate]

Possible Duplicate:
Android: Strange out of memory issue while loading an image to a Bitmap object

i am downloading images from Url and displaying them. At download time it is giving out of memory error : bitmap size exceeds VM budget. I am using drawable. Code is below:

HttpClient httpclient= new DefaultHttpClient(); HttpResponse response=(HttpResponse)httpclient.execute(httpRequest); HttpEntity entity= response.getEntity(); BufferedHttpEntity bufHttpEntity=new BufferedHttpEntity(entity); InputStream instream = bufHttpEntity.getContent();  Bitmap bm = BitmapFactory.decodeStream(instream); Bitmap useThisBitmap =  Bitmap.createScaledBitmap(bm,bm.getWidth(),bm.getHeight(), true); bm.recycle(); BitmapDrawable bt= new BitmapDrawable(useThisBitmap); System.gc(); 

Here is the error:

`05-28 14:55:47.251: ERROR/AndroidRuntime(4188):   java.lang.OutOfMemoryError: bitmap size exceeds VM budget` 
like image 841
Andy Avatar asked May 28 '10 09:05

Andy


1 Answers

Use decodeStream(is, outPadding, opts) with

BitmapFactory.Options opts=new BitmapFactory.Options(); opts.inDither=false;                     //Disable Dithering mode opts.inPurgeable=true;                   //Tell to gc that whether it needs free memory, the Bitmap can be cleared opts.inInputShareable=true;              //Which kind of reference will be used to recover the Bitmap data after being clear, when it will be used in the future opts.inTempStorage=new byte[32 * 1024];  
like image 131
Sando Avatar answered Sep 20 '22 03:09

Sando