I’m using a BitmapFactory to decode a JPG from file and then setting the imageBitmap of an ImageView with that. Sometimes, the app crashes with “java.lang.OutOfMemoryError: bitmap size exceeds VM budget“
I’ve tried using:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
Bitmap bm = BitmapFactory.decodeFile(filepath, options);
it seemed to be working for a while, but not anymore. What can I do?
In Android, there is a cap on how much memory that can be allocated to an application, it could be around 16 MB to 32 MB. (Upto Android Version)
For a 2 Mega Pixel, memory required for the bitmap would be 2 * 4 = 8 M.
To reduce memory consumption, you need to lower the image resolution. Say WVGA, 800×480 to start with
Shash