首页javaimageJava Graphics - 如何使图像逆时针旋转

Java Graphics - 如何使图像逆时针旋转

我们想知道如何使图像逆时针旋转。
import java.awt.geom.AffineTransform;
import java.awt.image.AffineTransformOp;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

public class Main {
  public static void main(String[] args) throws java.io.IOException {
    BufferedImage img = ImageIO.read(new File("input-image.png"));

    BufferedImage rotated = new AffineTransformOp(
        AffineTransform.getQuadrantRotateInstance(3, img.getWidth() / 2,
            img.getHeight() / 2), AffineTransformOp.TYPE_BILINEAR).filter(img,
        null);

    ImageIO.write(rotated, "PNG", new File("output-image.png"));
  }
}