[問題] 有關於BufferImaged
想請板上的大大們幫忙解釋一下我所碰到的問題
程式碼將每個pixel的RGB值所讀取的code
讀取上並沒太大的問題
import java.io.*;
import javax.imageio.*;
import java.awt.image.*;
public class pict {
public static void main(String[] args) throws IOException {
File file = new File("1.jpg");
BufferedImage image = ImageIO.read(file);
int width = image.getWidth();
int height = image.getHeight();
int r[][]=new int [width][height];
int g[][]=new int [width][height];
int b[][]=new int [width][height];
for (int x = 0; x < width; x++) {// for each pixel x
for (int y = 0; y < height; y++) {// for each pixel y
{
int rgb = image.getRGB(x, y);
System.out.printf("%x ", rgb);
r[x][y]=(rgb >> 16) & 0xff;
g[x][y]=(rgb >> 8) & 0xff;
b[x][y]=rgb & 0xff;
System.out.printf("%d %d %d ", r[x][y], g[x][y], b[x][y]);
}
}
}
}
}
若讀取的值為小畫家預設的那些顏色(似乎都是16的倍數和255) 就不會有問題
但若讀取值為自訂值 EX:RGB=(145,32,48) 則輸出會是 ff912131 145 33 49
會有一點差別 希望麻煩板上的大大們可以幫忙 謝謝~~
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.24.3.59
→
10/10 08:32, , 1F
10/10 08:32, 1F
→
10/10 08:35, , 2F
10/10 08:35, 2F
→
10/10 23:52, , 3F
10/10 23:52, 3F