繁体   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