java AffineTransform 图片 向右旋转90度

package test;


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 Pic {


public static void main(String[] args) throws Exception {
BufferedImage bi = transform(ImageIO.read(new File("src/test/ccsJLPT.JPG")));
   ImageIO.write(bi, "jpg", new File("src/test/out.jpg"));
}
private static BufferedImage transform(BufferedImage originalImage) {

AffineTransform tx = new AffineTransform();


// last, width = height and height = width :)
tx.translate(originalImage.getHeight() / 2,originalImage.getWidth() / 2);
tx.rotate(Math.PI / 2);
// first - center image at the origin so rotate works OK
tx.translate(-originalImage.getWidth() / 2,-originalImage.getHeight() / 2);


AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_BILINEAR);


// new destination image where height = width and width = height.
BufferedImage newImage =new BufferedImage(originalImage.getHeight(), originalImage.getWidth(), originalImage.getType());
op.filter(originalImage, newImage);


   return newImage;
}


}

你可能感兴趣的:(java)