簡體   English   中英

如何設置AffineTransform旋轉而不是剪切?

[英]How to set AffineTransform to rotate instead of shear?

在使用Graphics2D繪圖時,我使用AffineTransform。 在繪制之前,我用它來變換形狀。 rx和ry應該是旋轉的,但是在繪制圖形時,剪切的形狀不會旋轉。 如何執行輪換? 我嘗試使用默認構造函數,然后調用旋轉,縮放和平移,但是形狀看起來並不像它們應該看起來的那樣。

transform = new AffineTransform(sx, rx, ry, sy, tx, ty);
transform.createTransformedShape(shape); // Where shape is a GeneralPath instance

閱讀將仿射變換應用於圖像文章。

您需要使用rotate方法來獲得正確的旋轉。

您可以使用類似的旋轉方法

transform = g2d.getTransform();
transform.rotate(Math.toRadians(angleInDegree), pivotX, pivotY);
g2d.setTransform(transform);    
// draw anything and it will be rotated based on rotate method
transform.rotate(Math.toRadians(0), pivotX, pivotY);
g2d.setTransform(transform); // now further drawing will no be drawn rotated

暫無
暫無

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

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