我有一个矩形:Rect r = new Rect();
。我想将r
对象旋转45度。我查找了解决方案,并发现可以使用矩阵来实现:
Matrix m = new Matrix();
// point is the point about which to rotate.
m.setRotate(degrees, point.x, point.y);
m.mapRect(r);
问题在于当我将
r
传递给m.mapRect(r);
时,它会抱怨r
应该是RectF
类型。我设法这样做:RectF r2 = new RectF(r);
Matrix m = new Matrix();
// point is the point about which to rotate.
m.setRotate(degrees, point.x, point.y);
m.mapRect(r2);
但问题在于我需要类型为
Rect
而不是RectF
的对象。因为我要将r
对象传递给外部类,该类接受Rect
对象。
除了这种方法并且不旋转整个画布(画布包含其他元素),是否还有其他方法可以旋转类型为Rect
的矩形r
?
谢谢您的帮助!
最好的问候,Dimitar Georgiev