Rotating an Image in java

后端 未结 1 1557
误落风尘
误落风尘 2021-01-13 01:47

I have an image of a Pan Card and when I try to rotate it by 45 degrees and save it, I get a cropped image. Code to rotate an image is:

    BufferedImage dim         


        
相关标签:
1条回答
  • 2021-01-13 02:32

    Have a look at this example, using AffineTransform:

    http://www.billthelizard.com/2008/07/rotate-image-in-java.html

    there's some code to load the image, then this is the core:

    private Image image;
    AffineTransform identity = new AffineTransform();
    
    Graphics2D g2d = (Graphics2D)g;
    AffineTransform trans = new AffineTransform();
    trans.setTransform(identity);
    trans.rotate( Math.toRadians(45) );
    g2d.drawImage(image, trans, this);
    
    0 讨论(0)
提交回复
热议问题