我有一个以PNG格式编码的位图。如何确定黑色哪里是白色?
final int[] p = new int[1];
int iter = 0;
for (int i = 0; i < image.getWidth(); i++) {
for (int j = 0; j < image.getHeight(); i++) {
pixels[iter] = image.getData().getPixel(i, j, p)[0];
iter++;
}
}
每个像素总是返回1个。
答案 0 :(得分:0)
根据图像的编码方式,像素被打包成一个整数,Sa例如BufferedImage.TYPE_4BYTE_ABGR高字节是alpha,接着是蓝色,绿色然后是红色。
答案 1 :(得分:0)
BufferedImage image = ImageIO.read(file);
// Getting pixel color by position x=100 and y=40
int clr= image.getRGB(100,40);
int red = (clr & 0x00ff0000) >> 16;
int green = (clr & 0x0000ff00) >> 8;
int blue = clr & 0x000000ff;
红色,绿色和蓝色将是x = 100和y = 40
的像素的RGB值