Out of memory error with loading image

*爱你&永不变心* 提交于 2019-12-02 05:33:05

问题


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:


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



来源:https://stackoverflow.com/questions/10436927/out-of-memory-error-with-loading-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!