0
我想旋轉圖像沒有標準方法,使顏色數組和操作它,但是當我調用,旋轉我得到黑點(看圖片)我試圖旋轉沒有lib,但它使黑色點在圖片
這裏是我的代碼,colScaled是我試圖轉換成數組圖片:
public void arrays() {
colScaled = zoom2();
int j = 0;
int i = 0;
angel = Integer.parseInt(this.mn.jTextField1.getText());
float degree = (float) Math.toRadians(angel);
float cos = (float) Math.cos(degree);
float sin = (float) Math.sin(degree);
int W = Math.round(colScaled[0].length * Math.abs(sin) + colScaled.length * Math.abs(cos));
int H = Math.round(colScaled[0].length * Math.abs(cos) + colScaled.length * Math.abs(sin));
int x;
int y;
int xn = (int) W/2;
int yn = (int) H/2;
int hw = (int) colScaled.length/2;
int hh = (int) colScaled[0].length/2;
BufferedImage image = new BufferedImage(W + 1, H + 1, im.getType());
for (i = 0; i < colScaled.length; i++) {
for (j = 0; j < colScaled[0].length; j++) {
x = Math.round((i - hw) * cos - (j - hh) * sin + xn);
y = Math.round((i - hw) * sin + (j - hh) * cos + yn);
image.setRGB(x, y, colScaled[i][j]);
}
}
ImageIcon ico = new ImageIcon(image);
this.mn.jLabel1.setIcon(ico);
}
[Java像素數組旋轉]的可能重複(http://stackoverflow.com/questions/29739809/java-rotation-of-pixel-array) – Spektre
「黑色點」在哪裏?在圖像中還是在圖像周圍? – gpasch
在圖像中,周圍不是問題 –