Reputation: 25
I load image from url. it' ok, but when long time it error outofmemory: bitmap size exceeds vm budget. here my code
BitmapFactory.Options bmOptions;
bmOptions = new BitmapFactory.Options();
bmOptions.inJustDecodeBounds = true;
//from web
try {
Bitmap bitmap=null;
InputStream is=new URL(url).openStream();
BitmapFactory.decodeStream(is, null, bmOptions);
is.close();
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = 1;
is = new URL(url).openStream();
bitmap = BitmapFactory.decodeStream(is, null, o2);
is.close();
return bitmap;
} catch (Exception ex){
ex.printStackTrace();
return null;
}
help me please!!
Upvotes: 0
Views: 1263
Reputation: 1074
Try using the sampleSize of BitmapFactory.Options, this will reduce the size in memory of your image (and the quality)
But if your image is really too big, I think that's there no miracle solution, the image is simply too big ...
Upvotes: 2
Reputation: 1348
Just a idea, it could be this piece of code throws sometime a exception. This will causes that the InputStream will not release rthe asigned resources (memory leak).
if you close the Input stream in a finaly block this issue should be solved
Upvotes: 0
Reputation: 1638
Try with any other image. As this image is exceding the size of ur folder.
R u using Emulator to test it?
Upvotes: 0
Reputation: 74780
Your problem is exactly what stated in error message: your image is too big to be loaded into memory.
Upvotes: 1