2010-05-19 42 views
0

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

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

回答

0

可以使用旋轉方法一樣

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