我有以下代码来获取RGB
的像素值BufferedImage bi=ImageIO.read(new File("C:/Users/MyDell/workspace/Chaotic/bear.jpg"));
int[] pixel;
for (int y = 0; y < bi.getHeight(); y++) {
for (int x = 0; x < bi.getWidth(); x++) {
pixel = bi.getRaster().getPixel(x, y, new int[3]);
System.out.println(pixel[0] + " - " + pixel[1] + " - " + pixel[2] + " - "(bi.getWidth() * y + x));
}
}
如何将RGB的像素值更改为新值?
答案 0 :(得分:1)
您可以在BufferedImage img
上设置单个像素,如下所示:
int r = // red component 0...255
int g = // green component 0...255
int b = // blue component 0...255
int col = (r << 16) | (g << 8) | b;
img.setRGB(x, y, col);
查看here了解详情。