作者hsnuhrt (Ray)
看板java
标题[问题] 有关於BufferImaged
时间Sun Oct 10 08:20:05 2010
想请板上的大大们帮忙解释一下我所碰到的问题
程式码将每个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
1F:→ sbrhsieh:会有差别是跟什麽比较?把图存成 jpg 会失真...不能用 10/10 08:32
2F:→ sbrhsieh:未存成 jpg 前的影像来比对 jpg decode 後的影像 10/10 08:35
3F:→ hsnuhrt:应该跟这无关 因为bmp也是 10/10 23:52