Android, image loading and memory allocations -
i have app contains several custom views extend view. each custom view loads bunch of images (~20) , scales them down:
mbmp[img1] = bitmapfactory.decodestream(context.getassets().open("img01.png")); mbmp[img2] = bitmapfactory.decodestream(context.getassets().open("img02.png")); mbmp[img3] = bitmapfactory.decodestream(context.getassets().open("img03.png")); ... mbmp[img20] = bitmapfactory.decodestream(context.getassets().open("img20.png"));
this within try - catch block.
this part not cause problem. however, once reach point of scaling images , call scale method uses createscaledbitmap:
protected void scaleimages(float mwidth, float mheight) { float mxrat = mwidth/1024; float myrat = mheight/600; (int = 0; < mbmp.length; i++) { float oldx = mbmp[i].getwidth(); float oldy = mbmp[i].getheight(); double newx = (mxrat * oldx); double newy = (myrat * oldy); bitmap newbmp = bitmap.createscaledbitmap(mbmp[i], (int) newx, (int) newy, true); mbmp[i] = newbmp; } }
i error trying allocate memory.
01-25 10:16:44.227: error/dalvikvm-heap(14548): 1497600-byte external allocation large process. 01-25 10:16:44.227: error/dalvikvm(14548): out of memory: heap size=4871kb, allocated=2544kb, bitmap size=18683kb 01-25 10:16:44.227: error/graphicsjni(14548): vm won't let allocate 1497600 bytes
no single image of mine should take kind of memory when expanded ram, why running out when trying resize them?
this not single imagesize .this message shown bcoz u r decoding bitmap , stored in heap temp.so displaying tht msg.
Comments
Post a Comment