Reputation: 13
I have a large image 1.28 MB (1,343,488 bytes) that I use in my app, however I wanted to change a few things and created a new image that was instead only 292 KB (299,008 bytes) in size. I created both images in Photoshop 7.0, saved them both as .png and both as interlaced. I have been creating this app around the larger image, and as soon as I switch to the smaller image, I get an OutOfMemory error with my bitmap saying
12108912-byte external allocation too large for this process
why does it think my new image is 11.5 MB? if i switch images back to the larger one, it compiles correctly.
private Bitmap loadMapBitmap() {
Log.d("InteractiveMap", "loadBitmap");
Bitmap bitmap = null;
try {
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.map);
} catch (Resources.NotFoundException e) {
Log.d(TAG, "loadMapBitmap - " + e.toString());
finish();
} catch (OutOfMemoryError e) {
Log.d("InteractiveMap", "too big " + e.getMessage());
finish();
}
return bitmap;
}
I dont get why the much smaller image doesnt work.
Upvotes: 1
Views: 1442
Reputation:
It's the image resolution. The file size is not relevant. When you load a bitmap into memory, each pixel takes 4 bytes when using the ARGB8888
format
(which is the default one for BitmapFactory.decode..()
).
Example: A 640x480 pixel sized image takes 640*480*4
bytes, which is 1200kB in memory.
This is completely independend from the file-format used to compress this image (PNG, JPEG, ..) and filesize.
In extreme cases these sizes differ a lot. E.g. you create a huge image which consists of one color. That's pretty great when it comes to file compression. But in memory it will take a lot of space.
Upvotes: 2