-1

Is there any easy way to remove the chromakey from the image by java? I've tried to read about openCV and that's to hard to learn and use.

DimaZet
  • 3
  • 1
  • You question lacks detail, please read [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) – anastaciu Feb 04 '20 at 22:01

1 Answers1

0

The easiest solution with would be to do the manipulation Pixel by Pixel. For that to work you need an Image with an Alpha Channel. Pass TYPE_INT_ARGB to the Constructor of BufferedImage after width and height.

Then Copy in two nested for Loops each pixel to the new Image like this:

BufferedImage newImg = new BufferedImage(origImg.getWidth(), origImg.getHeight(), BufferedImage.TYPE_INT_ARGB);
Color background = new Color(0,0,0,0); //RGBA
for (int x = 0; x < origImg.getWidth(); x++) {          
   for (int y=0; y < origImg.getHeight(); y++) {
      Color newColor = new Color(origImg.getRGB(x, y) | 0xff000000, true);

      if(/*check for chromakey color*/)
        newImg.setRGB(x, y, background.getRGB())
      else
        newImg.setRGB(x, y, newColor.getRGB());            
   }      
}

This assumes you dont have an alpha component in the original Image, because it will be overwritten by the |0xff000000 with 255.

Lennart Deters
  • 158
  • 1
  • 9