Skip to content Skip to sidebar Skip to footer

Android: Error Loading Images: Outofmemoryerror: Bitmap Size Exceeds Vm Budget

I'm developing an Android Application for a tablet (1024x768). I searched and find some solutions here, but anyone solved me the problem. The application has 5 screens and each scr

Solution 1:

Try to load the image in the onCreate() method instead of loading it from the XML.

Have you tried to first read the dimensions and type of the image, and then load a scaled down version of that image?

As the Android developer resources suggest.

Solution 2:

1024x768 is the dimensions in DP, the number of pixels could be up to twice that on a high resolution device.

If you decode a 1024x768 image with a bitmapfactory it will scale the bitmap relative to density, so you could end up with a 2048x1536 image, which would take up something like 12MB.

If you always want the image to be the same resolution regardless of device resolution, than put it in the Drawable-nodpi folder, that will cause it not to be resized on decode.

Solution 3:

first of all, calling System.gc() won't really make the Garbage Collector pass, and it can really hinder your performance so I'd restrain myself from using it so widely. If you want the garbage collector to clean the images, use WeakReferences instead, and store the images on a HashMap.

Second of all, try to use smaller images, as the VM will quickly collapse instead.

Post a Comment for "Android: Error Loading Images: Outofmemoryerror: Bitmap Size Exceeds Vm Budget"