简体   繁体   English

如何设置AffineTransform旋转而不是剪切?

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

I use the AffineTransform when drawing with Graphics2D. 在使用Graphics2D绘图时,我使用AffineTransform。 I use it to transform a Shape before drawing it. 在绘制之前,我用它来变换形状。 rx and ry are supposed to be rotation but when drawing the shapes are sheared not rotated. rx和ry应该是旋转的,但是在绘制图形时,剪切的形状不会旋转。 How can I enforce rotation? 如何执行轮换? I tried using the default constructor then calling the rotate, scale and translate but the shapes looked nothing like they're supposed to look. 我尝试使用默认构造函数,然后调用旋转,缩放和平移,但是形状看起来并不像它们应该看起来的那样。

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

Read Applying Affine Transformation to Images article. 阅读将仿射变换应用于图像文章。

You need to use rotate method to get correct rotation. 您需要使用rotate方法来获得正确的旋转。

You can use rotate method like 您可以使用类似的旋转方法

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