java - 设置新的像素值

标签 java image rgb

我有以下代码来获取 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/

相关文章:

java - 如何让特定的类(class)成员处于混淆状态?错误期望在 arg 之前分隔 ',' 或关闭 ')'

java - 在 Apache Camel 中访问拆分 entrySet 的主体

java - 短信广播接收器不工作

java - 关于在2D游戏中编写重力代码的问题

objective-c - 在 OpenGL 中显示 YUV

image - 在不可见区域绘制 VSIS 图像位图

java - 读取图像并通过套接字发送 - 无法打开文件

linux - 从硬盘中查找并复制所有图像

ffmpeg - 为什么我的 H.264 视频在应用视频滤镜后有绿色叠加层?

javascript - 操作 RGBA Javascript