a を回転させて a のBufferedImage
中に表示しようとしていますJLabel
( a の中にありますJPanel
)。現在の結果では、黒い背景に対して 10 度回転した白い正方形が生成されますが、画像は正方形内に存在しません。回転していない場合 、それ自体が の中に適切に表示されるmyPicture
ため、空白ではないことはわかっています。myPicture
JPanel
コードは次のとおりです。
int w = myPicture.getWidth();
int h = myPicture.getHeight();
BufferedImage newImage = new BufferedImage(w, h, myPicture.getType());
Graphics2D graphic = newImage.createGraphics();
graphic.rotate(Math.toRadians(10), w/2, h/2);
graphic.drawImage(myPicture, null, 0, 0);
picLabel.setIcon(new ImageIcon(newImage));