Obróć BufferedImage Inside JPanel
Próbuję obrócić aBufferedImage
i wyświetl go w aJLabel
(który jest wewnątrz aJPanel
). Bieżący wynik daje biały kwadrat obrócony o 10 stopni na czarnym tle, ale obraz nie jest obecny wewnątrz kwadratu. wiemmyPicture
nie jest pusty, ponieważmyPicture
wyświetla się poprawnie wewnątrzJPanel
gdy nie jest obracany.
Oto kod:
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));