简体   繁体   English

java中的setRGB()

[英]setRGB() in java

I am using setRGB() for changing the values of the pixel of an image. 我正在使用setRGB()来更改图像像素的值。

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

Here,i am setting all the pixel values with white. 在这里,我将所有像素值设置为白色。 But the change is not getting reflected in the image. 但这种变化并没有反映在图像中。 Any One knows about the setRGB() how it works? 任何人都知道setRGB()它是如何工作的?

White is in RGB 255,255,255 so: 白色是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) {
}
 Color col = new Color(newValue, newValue, newValue);
            image1.setRGB(i, j, col.getRGB());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM