我有以下代码来获取 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 像素值更改为新值?
最佳答案
您可以在 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了解更多信息。
关于java - 设置新的像素值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20861411/