java - Java 中的 setRGB()

标签 java image image-processing pixel

我正在使用 setRGB() 来更改图像的像素值。

int rgb=new Color(0,0,0).getRGB();
image1.setRGB(i,j,rgb); //where i,j is the boundaries of the image

在这里,我将所有像素值设置为白色。但是这种变化并没有反射(reflect)在图像中。任何人都知道 setRGB() 它是如何工作的?

最佳答案

白色在 RGB 255,255,255 中,所以:

Color myWhite = new Color(255, 255, 255); // Color white
int rgb = myWhite.getRGB();

try {
    BufferedImage img = null;
    try {
        img = ImageIO.read(new File("bubbles.bmp"));
    }
    catch (IOException e) {
    }

    for (int i = 0; i < 100; i++) {
        for (int j = 0; j < 100; j++) {
            img.setRGB(i, j, rgb);
        }
    }

    // retrieve image
    File outputfile = new File("saved.png");
    ImageIO.write(img, "png", outputfile);
}
catch (IOException e) {
}

关于java - Java 中的 setRGB(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11951646/

相关文章:

java - 如何部署到Intellij IDEA Tomcat文件夹?

c# - 从调整大小的图像中翻译/检测图像的矩形部分

css - 仅使用 CSS,裁剪 .image 保持纵横比不失真

image - RGB图像转二值图像

python - 将图像编辑为 tensorflow 张量 python

OpenCV 使用 Hue channel 对货币进行分类

java - 为什么 PendingIntent 会被触发?

java - 在不安装 SMTP 服务器的情况下测试 Greenmail

java - EJB - 如何按非索引字段搜索?

css - 背景图像技术