I need a small help on rotating one image around its center of axis among multiple images which are drawn to canvas in android.
I am loading images to canvas like below.
canvas.drawBitmap(mMachineBackground, 0, 0, null);
canvas.drawBitmap(mMachineRotator, 0, 0, null);
I want to rotate only the second bitmap around its center of axis instead of rotating the entire canvas(which includes first bitmap also).
Thanks in advance.
You can rotate around the centre axis:
Matrix matrix = new Matrix();
//move image
matrix.setTranslate(getXPos() - (imageWidth / 2), getYPos() - (imageHeight / 2));
//rotate image, getXPos, getYPos are x & y coords of the image
matrix.postRotate(angleInDegrees, getXPos() - imageWidth / 2, getYPos() - imageHeight / 2);
//rotatedBMP is the image you are drawing,
canvas.drawBitmap(rotatedBMP, matrix, Paint);
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