0
votes

I have an image that I want to rotate, like a watch hand. The problem is that no matter what I'm putting in the pivot point (in the matrix.setrotate) is still rotated the same. Here is my code:

c = holder.lockCanvas();
matrix.setRotate((float) degre * 4, 500, 500);
Bitmap to_rotate = Bitmap.createBitmap(watch_hand, 0, 0, watch_hand.getWidth(), watch_hand.getHeight(), matrix, false);
c.drawARGB(255, 255, 255, 255);
c.drawBitmap(background, 0, 0, null);
c.drawBitmap(to_rotate, CENTER_X - 20 , CENTER_Y - height / 2 + 20, null);
holder.unlockCanvasAndPost(c);

What can I do?

I want the image to rotate at "CENTER_X, CENTER_Y.

1

1 Answers

0
votes

I found an answer. I used this and it works OK:

canvas = holder.lockCanvas(); 

matrixUP.setTranslate(CENTER_X - watch_hand.getWidth()/2, height/4 - watch_hand.getHeight() - 40); matrixUP.preRotate((float) degreUP , watch_hand.getWidth()/2 , watch_hand.getHeight()-10); canvas.drawBitmap(watch_hand, matrixUP, null); 

holder.unlockCanvasAndPost(canvas);