简体   繁体   中英

Android Java - Rotate Bitmap causes GC_FOR_ALLOC

I'm trying to set a bitmap's rotation using a matrix but I am having some trouble here.

Does anyone know how to rotate a bitmap?? I am so confused why this would give out of memory errors. My code is plain and simple:

thisRotation = Math.toDegrees(Math.atan2(
            (fingery1 - thisRectf.centerY()),
            (fingerx1 - thisRectf.centerX()))));
matrix.setRotate(thisRotation, thisRectf.centerX(),
            thisRectf.centerY());
Bitmap.createBitmap(thisBitmap, 0, 0, thisBitmap.getWidth(), 
                         thisBitmap.getHeight(), matrix, true);

I have used google and apparently this is not an easy fix? My image is very small (9 kb) and i've tried lowering it to 900 bytes but it still causes gc.

I was using a custom view, and in my onDraw method, I used

canvas.drawBitmap(bitmap, srcRectf, dstRectf, paint);

to draw my bitmap, but I should have been using

canvas.drawBitmap(bitmap, matrix, paint);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM