我想旋轉圖像。我使用這個Java代碼:Java - 圖像旋轉
BufferedImage oldImage = ImageIO.read(new FileInputStream("C:\\workspace\\test\\src\\10.JPG"));
BufferedImage newImage = new BufferedImage(oldImage.getHeight(), oldImage.getWidth(), oldImage.getType());
Graphics2D graphics = (Graphics2D) newImage.getGraphics();
graphics.rotate(Math.toRadians(90), newImage.getWidth()/2, newImage.getHeight()/2);
graphics.drawImage(oldImage, 0, 0, oldImage.getWidth(), oldImage.getHeight(), null);
ImageIO.write(newImage, "JPG", new FileOutputStream("C:\\workspace\\test\\src\\10_.JPG"));
但我看到奇怪的結果:
來源:
結果:
**Result image:** http://s14.postimage.org/cjut935ip/image.jpg
能否請你幫我有這個問題嗎?
難道你不應該旋轉關於oldImage的中心,而不是newImage? –
我嘗試 graphics.rotate(Math.toRadians(90),oldImage.getWidth()/ 2,oldImage.getHeight()/ 2); 它沒有幫助。 http://s13.postimage.org/7omxa1oef/image.jpg – user1631241