i'm trying to write a code that masks red and blue channel from the image inputted.I have retrieved r,g,b values but however stuck up in proceeding further.I'm just a beginner.Can anyone help me in this please?

public class Green
    public static void main(String args[]) throws IOException

        BufferedImage bi= ImageIO.read(new File( "image.jpg" );      
        for (int x=0; x <= bi.getWidth(); x++){          
      for (int y = 0; y <= bi.getHeight(); y++){                         
         int pixelCol=bi.getRGB(x,y);              
       int r= (pixelCol>>16) & 0xff;
      int b = pixelCol & 0xff;
         int g = (pixelCol>>8) & 0xff;
              int px=0;
5 Years
Discussion Span
Last Post by JamesCherrill

You have code to split out the RGB values from each pixel, so now you need some similar code to combine RGB values into a single int pixel. Between splitting them and re-combining them you can set r, g, and/or b to zero.

Or, you can use bi.getRaster().getDataBuffer(); to get direct (RW) access to the pixels, so you can modify and replace them one at a time. You can use & to zero out individual bytes each pixel.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.