我想在Java中逐個像素地操縱圖像,所以我已經建立了一個包含我的顏色的一維列表。然後我將其轉換爲緩衝圖像,但像素全部錯誤。在java中將數組轉換爲bufferedimage的難度
所以我把它簡化到下面的絕對基礎。在我看來,這應該給一個廣場,左半邊藍色,右邊有黑色。相反,它會產生藍色和黑色的斜條紋。有關正在發生什麼的任何想法?
private void create(){
int w = 100;
int h = 100;
int blue;
int[] pix = new int[w * h];
int index = 0;
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
if (x<50) {blue = 255;}
else blue=0;
pix[index++] = blue;
}
}
image = new BufferedImage(100,100, BufferedImage.TYPE_INT_RGB);
image.setRGB(0, 0, 100, 100, pix, 0, 1);
檢查這個,也許它會幫助你:http://stackoverflow.com/questions/9396159/how-do-i-create-a-bufferedimage-from-array-containing-pixels –