Rotate the rectangle to swing the image

I have an image on JPanel. Then I draw a rectangle over the image as follows:

Graphics2D image = (Graphics2D) g;
image.drawRect(......);
//create image code here.
image.rotate(1.5);
image.drawImage(....);

The problem is that when I rotate the image.rotate (1.5) image, the rectangles remain in the same place.

I tried to create a rectangle before rotating the image and after rotating the image, but both times it fails.

Is there an easy way to make the rectangles also rotate with the image?

Thank.

+3
source share
2 answers

One approach is to rotate the affine transform of the graphics context, as shown in the example. Thus, the entire pattern will be rotated by the same amount.

+1
source

, Rectangle, Rectangle2D, g2d.draw(). Graphics2D.

0

Source: https://habr.com/ru/post/1792097/


All Articles