java中的setRGB()

java中的setRGB(),java,image,image-processing,pixel,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 在这里,我用白色设置所有像素值。但这一变化并未反映在图像中。任何人都知道setRGB()它是如何工作的?白色在RGB 255255中,因此: Color myWhite = new Color(255, 255, 255); // Color whi

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

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

在这里,我用白色设置所有像素值。但这一变化并未反映在图像中。任何人都知道
setRGB()
它是如何工作的?

白色在RGB 255255中,因此:

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 myWhite=新颜色(255、255、255);//白色
int rgb=myWhite.getRGB();
试一试{
BuffereImage img=null;
试一试{
img=ImageIO.read(新文件(“bubbles.bmp”);
}
捕获(IOE异常){
}
对于(int i=0;i<100;i++){
对于(int j=0;j<100;j++){
img.setRGB(i,j,rgb);
}
}
//检索图像
File outputfile=新文件(“saved.png”);
写入(img,“png”,outputfile);
}
捕获(IOE异常){
}

可能是另一个错误或您走错了路。因此,请发布更多代码。几点….-颜色(0,0,0)将为黑色-setRGB设置图像中的单个像素,而不是整个图像RGB颜色图表什么是
image1
?仅供参考:RGB值
0,0,0
映射为黑色,而RGB值
255255255
映射为白色
setRGB(0,0,0)
并告知结果。如果这回答了您的问题,请接受它作为答案,以便将问题标记为已回答。
 Color col = new Color(newValue, newValue, newValue);
            image1.setRGB(i, j, col.getRGB());