Android Studio bitmap allocation out-of-memory error -
i'm using function rotate bitmap camera or gallery:
public static bitmap fixorientation(bitmap mbitmap) { if (mbitmap.getwidth() > mbitmap.getheight()) { matrix matrix = new matrix(); matrix.postrotate(90); return bitmap.createbitmap(mbitmap , 0, 0, mbitmap.getwidth(), mbitmap.getheight(), matrix, true); // error here! } return mbitmap; }
its workes fine in first 2 times i'm using it, in third time crashes app , giving me error:
java.lang.outofmemoryerror: failed allocate 36578316 byte allocation 16771872 free bytes , 29mb until oom
this function called:
@override protected void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); if (resultcode == result_ok && data != null) { uri uri = data.getdata(); try { bitmap sourcebitmap = mediastore.images.media.getbitmap(this.getcontentresolver(), uri); bitmap correctbitmap = fixorientation(sourcebitmap); image.setimagebitmap(correctbitmap); bitmapsarray[camerasideint] = correctbitmap; chooseimagelayout.setvisibility(view.gone); // show change layout } catch (ioexception e) { e.printstacktrace(); } } }
can think of way solve error?
yeah- don't save many bitmaps. you're storing them in array. bitmaps take lots of memory. while they're in array can't garbage collected, memory lost. shouldn't doing this.
you can other memory leaks in app, exist , may save enough memory make doable. bad idea, if bitmaps large (anything close full screen).
Comments
Post a Comment