I have an Image and I’m able to draw a rectangle on the image like this:
Rectangle rect = new Rectangle(x,y,width,height);
graphics2D.draw(rect);
Then I rotate the Image and the drawn rectangle also rotates as expected. But now how can I get a reference to the newly rotated Rectangle? I need the properties of the rotated Rectangle like Point, width, height….
I don’s see that Graphics2D has a method like getShape()? Also, the rectangle passed to the Graphics2D when calling its draw(Rectangle) method doesn’t change.
Any ideas?
You can do it using AffineTransform class.
But it would yield you only the shape, which you can use for drawing. If you need exact points of rotated rectangle, you’ll need to transform each point separately: