Out of memory error with loading image

2019-02-25 18:39发布

I want to load an image on android

background = BitmapFactory.decodeResource(getResources(),R.drawable.hangmanbegin);    
background =  Bitmap.createScaledBitmap(background,screenx,screeny,false);

The image is 800*1280 pixels , so if I'm correct it should use arround 3MB of memory space? But my heap grows from 15MB to 29MB just at that phase , so no window or context leaking?

How is this explained? en what can you do about it?

Thnx in advance!

1条回答
我只想做你的唯一
2楼-- · 2019-02-25 19:14

Bitmaps take up a lot of memory, especially for rich images like photographs. For example, the camera on the Galaxy Nexus takes photos up to 2592x1936 pixels (5 megapixels). If the bitmap configuration used is ARGB_8888 (the default from the Android 2.3 onward) then loading this image into memory takes about 19MB of memory (2592*1936*4 bytes), immediately exhausting the per-app limit on some devices.

from http://developer.android.com/training/displaying-bitmaps/index.html

credit and below it a way to approach a fix https://stackoverflow.com/a/10127787/643500

查看更多
登录 后发表回答