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;
}


}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章