I'm using this to get rotated Bitmap
from existed one :
private Bitmap getRotatedBitmap(Bitmap bitmap, int angle) {
int w = bitmap.getWidth();
int h = bitmap.getHeight();
Matrix mtx = new Matrix();
mtx.postRotate(angle);
return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true);
}
Is it possible to do it without creating new bitmap?
I was trying to redraw the same mutable image with Canvas
:
Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight, config);
Canvas canvas = new Canvas(targetBitmap);
Matrix matrix = new Matrix();
matrix.setRotate(mRotation,source.getWidth()/2,source.getHeight()/2);
canvas.drawBitmap(targetBitmap, matrix, new Paint());
but this approach had just resulted in corrupted bitmap. So is there any possibilities to achieve it?
This is the simplest rotation on canvas code, without creating a new bitmap
canvas.save(); //save the position of the canvas
canvas.rotate(angle, X + (imageW / 2), Y + (imageH / 2)); //rotate the canvas
canvas.drawBitmap(imageBmp, X, Y, null); //draw the image on the rotated canvas
canvas.restore(); // restore the canvas position.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With