Eyad Salah
Eyad Salah

Reputation: 1103

How to set AffineTransform to rotate instead of shear?

I use the AffineTransform when drawing with Graphics2D. 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. 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

Upvotes: 0

Views: 1342

Answers (2)

Digvijaysinh Gohil
Digvijaysinh Gohil

Reputation: 1465

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

Upvotes: 1

Roman
Roman

Reputation: 66216

Read Applying Affine Transformation to Images article.

You need to use rotate method to get correct rotation.

Upvotes: 2

Related Questions