在android中,如何在绘制到画布的多个图像之间旋转特定图像?
我需要一个小的帮助,旋转一个图像围绕其轴的中心在多个图像是画在画布上的android 我正在将图像加载到画布,如下所示在android中,如何在绘制到画布的多个图像之间旋转特定图像?,android,animation,canvas,Android,Animation,Canvas,我需要一个小的帮助,旋转一个图像围绕其轴的中心在多个图像是画在画布上的android 我正在将图像加载到画布,如下所示 canvas.drawBitmap(mMachineBackground, 0, 0, null); canvas.drawBitmap(mMachineRotator, 0, 0, null); 我只想绕轴的中心旋转第二个位图,而不是旋转整个画布(也包括第一个位图) 提前谢谢。恐怕您不能这样做。 就我到目前为止所学的内容而言,您可以旋转整个上下文,但不能旋转单个位图。我所知
canvas.drawBitmap(mMachineBackground, 0, 0, null);
canvas.drawBitmap(mMachineRotator, 0, 0, null);
我只想绕轴的中心旋转第二个位图,而不是旋转整个画布(也包括第一个位图)
提前谢谢。恐怕您不能这样做。 就我到目前为止所学的内容而言,您可以旋转整个上下文,但不能旋转单个位图。我所知道的变换矩阵只能应用于整个画布。
(我不是画布大师,但我正在对你的同一个问题进行广泛的研究)你可以围绕中心轴旋转:
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);
这段代码是我根据上面代码的引用编写的,它工作得非常好
我可以在画布上旋转特定图像。您好,谢谢您的回复。我们不能使用旋转动画围绕位图的轴中心旋转位图吗。否则。我最好选择逐帧动画,以获得所需的旋转动画效果。提前谢谢。爱你的人…我已经找了4天了,最后你的答案给了我答案。非常感谢你。。。
//Drawing the Player Canon.
Matrix matrix = new Matrix();
//move image
newHeight = getHeight() - canon1[0].getHeight() - stand1.getHeight();
Log.d(TAG, "New Height : " + newHeight);
//matrix.setTranslate(0, getHeight() - canon1[0].getHeight() + stand1.getHeight());
matrix.setTranslate(-newHeight,newHeight);
// rotate image, getXPos, getYPos are x & y coords of the image (ANgle in degree)).
//matrix.postRotate(45, 0, getHeight() - canon1[0].getHeight() + stand1.getHeight());
matrix.postRotate(-30,0,0);
//Draw function.
canvas.drawBitmap(canon1[0], matrix, null);