可能重复:
旋转 BufferedImage 实例
我目前使用的方法(如下)导致 BufferedImage 变得越来越失真,角度参数越小。
public static BufferedImage getRotatedImage(BufferedImage src, int angle) {
if (src == null) {
System.out.println("getRotatedImage: input image is null");
return null;
}
int transparency = src.getColorModel().getTransparency();
BufferedImage dest = gc.createCompatibleImage(
src.getWidth(), src.getHeight(), transparency );
Graphics2D g2d = dest.createGraphics();
AffineTransform origAT = g2d.getTransform();
AffineTransform rot = new AffineTransform();
rot.rotate(Math.toRadians(angle), src.getWidth()/2, src.getHeight()/2);
g2d.transform(rot);
g2d.drawImage(src, 0, 0, null);
g2d.setTransform(origAT);
g2d.dispose();
return dest;