围绕在画布上的中心点旋转图像中心点、画布、图像

2023-09-05 10:34:52 作者:感受

旋转图像围绕其中心帆布。我试图从网上的一些例子,但我失败了。

rotate image on canvas around its center . i tried some example from net but i am failed

如果我使用 bitmap.creatbitmap 与矩阵我收到错误

if i am using bitmap.creatbitmap with matrix i am getting error

请建议我哪个更好

在此先感谢

阿斯旺

推荐答案

您可以用一个矩阵来旋转。首先,你(我使用的是位图的中心坐标)设定的位置。然后应用的旋转。然后绘制使用你的矩阵。

You can use a matrix to rotate. First you set the position (I'm using the coordinates of the bitmap's centre). Then apply a rotation. Then draw using your matrix.

    Matrix transform = new Matrix();
    transform.setTranslate(xOfCentre, yOfCentre);
    transform.preRotate(turnDegrees, width/2, height/2);
    canvas.drawBitmap(bitmap, transform, null);

如果你希望你的转折点是动画,然后看到my回答动画和旋转图像......。

If you want your turning to be animated, then see my answer to "animating and rotating an image...".

 
精彩推荐
图片推荐