围绕轴旋转图像

时间:2012-04-21 10:55:50

标签: android image matrix rotation

我有一个想要旋转的图像,就像一只手表。问题在于,无论我放在枢轴点(在matrix.setrotate中)仍然旋转相同。这是我的代码:

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);

我该怎么办?

我希望图像在“CENTER_X,CENTER_Y。

旋转

1 个答案:

答案 0 :(得分:0)

我找到了答案。我使用了它,它可以正常工作:

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);