android - OOM: Drawing a 3MB .png file on a canvas -


i trying draw bitmap (as background) on surfaceview's canvas

i tried:

drawable bg = contextcompat.getdrawable(surfaceview.getcontext(), r.drawable.bg); bg.draw(canvas); 

and tried:

bitmapfactory.options options = new bitmapfactory.options(); options.insamplesize = (int) (1600 / width);  //since width of image 1600px bitmapfactory.decoderesource(surfaceview.getresources(), r.drawable.bg, options); 

and both result in same oom exception

java.lang.outofmemoryerror: failed allocate 147456012 byte allocation 1048576 free bytes , 95mb until oom 

i appreciate on how draw .png image 3mb (1600*2560)

well, don't know why 3mb couldn't loaded on heap without oom

but adding large heap line manifest solved problem

<application     android:largeheap="true"     ...> 

hope it'll who'd face same problem :)


Comments