Rotate a Java Graphics2D Rectangle?

前端 未结 4 1760

I have searched everywhere and I just cant find the answer.
How do I rotate a Rectangle in java?

Here is some of my code:

package net.chrypthic.S         


        
4条回答
  •  心在旅途
    2020-11-28 11:45

    Another way is by using Path2D, with it you can rotate the path only and not the entire graphics object:

    Rectangle r = new Rectangle(x, y, width, height);
    Path2D.Double path = new Path2D.Double();
    path.append(r, false);
    
    AffineTransform t = new AffineTransform();
    t.rotate(angle);
    path.transform(t);
    g2.draw(path);
    

提交回复
热议问题