OutofMemoryError: bitmap size exceeds VM budget (Android)

后端 未结 9 731
甜味超标
甜味超标 2020-11-27 18:48

Getting an Exception in the BitmapFactory. Not sure what is the issue. (Well I can guess the issue, but not sure why its happening)

ERROR/AndroidRuntime(7906): jav         


        
9条回答
  •  北海茫月
    2020-11-27 19:20

    I got this error when i began to resize an image from 320x240 to something like 64x240 (downscale), then import into my project (since i wanted to improve rendering speed and it contained a lot of useless alpha regions until this point).

    now the last answer makes much sense:

    You can "expand" your heap by adding this static { @SuppressWarnings("unused") byte dummy[] = new byte[ 8*1024*1024 ]; } to your code, to force the heap to expand. It may make it a bit less frequent.

    I think this is what happened to me. Android automatically decodes drawables into bitmaps, (and then get stored on a heap, all on compilation time?)

    i began seeing the error, when i used the smaller version of my image in runtime (i scale them up on runtime since i program a VGA-game with retro graphics, using BitmapFactory.decodeResource and Bitmap.createScaledBitmap).

    it must be like Marve said: The Heap is not big enough in my case after shrinking my drawable/image and import it into my project.

    I was able to get rid of my OutOfMemoryException when resizing the image back to a bigger size (320x240), which verifies the problem i guess?

提交回复
热议问题