0

I have two TIF files, one is background (overlay) and the other is foreground. The following code is currently used for combining two TIFs.

    // Background color of foreground image
    int w = Color.WHITE.getRGB();

    // Fill all pixels which are not background color
    for (int i = 0; i < foregroundImage.getWidth(); i++)
    {
        for (int j = 0; j < foregroundImage.getHeight(); j++)
        {
            int x = foregroundImage.getRGB(i, j);
            if (x != w)
                backgroundImage.setRGB(i, j, x);
        }
    }

Is there any other way that has a better performance to do this?

1 Answers1

0

You can make the Color.white pixels transparent using RGBImageFilter, shown here, or LookupOp, mentioned here. Then you can use the AlphaComposite.SRC_OVER rule to combine the images. AlphaCompositeDemo is an example that lets one explore the available modes, and there's related example here. Of course, you'll need to profile both approaches to see which is faster.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045