1

I have a 300 x 355 image that is only 50 kb in size. I am trying to decode it with the below code:

Bitmap bm = BitmapFactory.decodeResource(getResources(), drawableId)
    .copy(Bitmap.Config.ARGB_8888, true);

According the logcat 10674000 bytes is trying to be allocated. Why so many? The image is only 50 kb.

4

1 回答 1

6

300 x 355 = 106500 pixels.

At 4 bytes per pixel, that is 426KB, which is closer to the allocation reported by your LogCat.

The .copy() command in your code will double the memory to 852KB, slightly closer to the 10.6MB reported.

The 50KB number you reported is probably the compressed size of the .jpg or .png file, not the uncompressed Bitmap being used by Android.

于 2013-03-29T21:43:20.800 回答