-2
您能評論這段代碼嗎?我理解一些部分,但不是全部。Java圖像旋轉
該代碼是一種圖像90度逆時針旋轉:
public static void rotate(String originalImage, String convertedImage) throws Exception {
BufferedImage bufferImg = ImageIO.read(new File(originalImage));
BufferedImage bufferImgOut = new BufferedImage(bufferImg.getWidth(),bufferImg.getHeight(), bufferImg.getType());
for(int x = 0; x < bufferImg.getWidth(); x++) {
for(int y = 0; y < bufferImg.getHeight(); y++) {
int px = bufferImg.getRGB(x, y);
int destY = bufferImg.getWidth() - x - 1; //what does this line do?
bufferImgOut.setRGB(y,destY, px);
}
}
File outputfile = new File(convertedImage);
ImageIO.write(bufferImgOut, "png", outputfile);
}
基本上,因爲搖擺座標系'開始出現Y = 0'在頂部,你必須翻轉x座標旋轉。 – Radiodef