Okay, I have a method that takes the variables: an image, int x, int y, float angle.
I am using a canvas, and I am using a Matrix transform = new Matrix(); to rotate the image at it’s center. However, I want the image to be drawn at the coordinates of x and y. For some reason, all the different methods I have used have not worked. Sometimes it draws it at 0,0 or it doesn’t even show up on the screen.
Here’s my pseudo-code:
//pseudo-code: img_width, img_height
public void drawImage(Bitmap img, int x, int y, float angle)
{
transform.setTranslate(x, y);
transform.setRotate(angle, img_width/2, img_height/2);
canvas.drawBitmap(img, transform, null);
}
I have gotten the image to rotate, but I want the image to be drawn at the specified coordinates: x,y.
I have tried swapping all the variables, used transform.preRotate, and basically spent 1 hour trying to figure out why nothing will work. I have lots of other images being drawn to the canvas, and they appear where they should, but when I want to rotate, it won’t draw at the specified coordinates.
I’ve read about 5 SO questions and answers related to this, but none give me what I need.
I really need an answer and code urgently, thank you.
Maybe you’d want to write :
If you translate the image before the rotation, the image won’t go where you expect it to…