簡體   English   中英

如何在Android中旋轉Rect對象

[英]How to rotate a Rect object in Android

好的,所以我使用此代碼在畫布上創建了一個Rectangle

Rect r =new Rect((point.x - rectWidth / 2), (point.y - rectHeight / 2),(point.x-rectWidth / 2),(point.y + rectHeight / 2));

point是由觸摸事件確定的矩形的中心。 但現在我希望能夠旋轉這個矩形。 是否有任何代碼或方法允許用戶圍繞其中心旋轉形狀。 我也有興趣獲得這樣一個矩形的角點。 任何幫助表示贊賞。 謝謝。

要圍繞其自己的中心旋轉矩形(而不是原點):

Matrix m = new Matrix();
// point is the point about which to rotate.
m.setRotate(degrees, point.x, point.y);
m.mapRect(r);

您還可以使用Matrix.mapPoints()來查找角點的轉換方式。

使用以下:

Rect r2 = new Rect(r1);
Matrix mat = new Matrix();
mat.setRotate(-90, r2.centerX(), r2.centerY());
mat.mapRect(r2);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM