setRGB() in java

前端 未结 2 1431
孤城傲影
孤城傲影 2020-12-16 19:25

I am using setRGB() for changing the values of the pixel of an image.

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


        
相关标签:
2条回答
  • 2020-12-16 19:40

    White is in RGB 255,255,255 so:

    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) {
    }
    
    0 讨论(0)
  • 2020-12-16 19:43
     Color col = new Color(newValue, newValue, newValue);
                image1.setRGB(i, j, col.getRGB());
    
    0 讨论(0)
提交回复
热议问题