0

我有两个 TIF 文件,一个是背景(覆盖),另一个是前景。以下代码当前用于组合两个 TIF。

    // 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);
        }
    }

有没有其他方法有更好的性能来做到这一点?

4

1 回答 1

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.

于 2012-06-30T00:42:41.280 回答