我找到了一種在Java中旋轉圖像的方法。Image Rotation Java
public static BufferedImage rotate(BufferedImage image, double angle)
{
double sin = Math.abs(Math.sin(angle)), cos = Math.abs(Math.cos(angle));
int w = image.getWidth(), h = image.getHeight();
int neww = (int) Math.floor(w * cos + h * sin), newh = (int) Math.floor(h * cos + w * sin);
GraphicsConfiguration gc = getDefaultConfiguration();
BufferedImage result = gc.createCompatibleImage(neww, newh, Transparency.TRANSLUCENT);
Graphics2D g = result.createGraphics();
g.translate((neww - w)/2, (newh - h)/2);
g.rotate(angle, w/2, h/2);
g.drawRenderedImage(image, null);
g.dispose();
return result;
}
但似乎在這條線
GraphicsConfiguration gc = getDefaultConfiguration();
當我將鼠標懸停我的鼠標在它的一個錯誤,它說:「該方法getDefaultConfiguration()是未定義的類型的球員」
這是我進口
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.Transparency;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.awt.GraphicsDevice;
import javax.imageio.ImageIO;