我有一张 Pan Card 的图像,当我尝试将其旋转 45 度并保存时,我得到了一张裁剪过的图像。 旋转图像的代码是:
BufferedImage dimg = new BufferedImage(w, h, img.getType());
Graphics2D g = dimg.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, // Anti-alias!
RenderingHints.VALUE_ANTIALIAS_ON);
g.rotate(Math.toRadians(angle), w / 2, h / 2);
g.drawImage(img, null, 0, 0);
最佳答案
看看this example , 使用仿射变换。
有一些加载图片的代码,那么这是核心:
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);
关于java - 在java中旋转图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10685016/