CANVAS:如何旋转指定其位置和大小的图像?

我需要在画布上显示图像,并且该图像必须在适当的位置并具有一定的大小,因为它在每次更新时都会增加其大小。

我是这样画的:

Drawable drawable = asteroid.getView().getDrawable();
drawable.setbounds(asteroid.getRect());
drawable.draw(canvas);

运行良好。 getRect()返回具有x,y,width,height的Rect,并且可以正常工作。

问题是,现在我需要向图像添加无限连续的旋转,就像一个球,必须以相同的旋转速度永远旋转,直到将其从屏幕上移除为止。

我看到可以使用以下方法进行旋转:

Matrix matrix = new Matrix();
matrix.setRotate(angle,imageCenterX,imageCenterY);
yourCanvas.drawBitmap(yourBitmap,matrix,null);

问题是我无法将这两个代码段合并在一起,因为如果使用drawBitmap,则无法使用该位图的x,y和宽度/高度指定Rect。

以前,使用对象动画师是这样进行的:

rotation = ObjectAnimator.ofFloat(view,"rotation",360f,0f);
rotation.setDuration(rotationTime);
rotation.setInterpolator(null); 
rotation.setRepeatCount(ObjectAnimator.INFINITE);

如何解决这个问题?

bmliuxuan142524 回答:CANVAS:如何旋转指定其位置和大小的图像?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3152592.html

大家都在问