1

鉴于此示例代码将所有蓝色替换为新背景:

public void chromakeyBlue(Picture newBg)
{
    Pixel [] pixelArray = this.getPixels();
    Pixel currPixel = null; 
    Pixel newPixel = null;

    for (int i = 0; i < pixelArray . length ; i++) { 
        currPixel = pixelArray [ i ];

        if (currPixel.getRed() + currPixel.getGreen() < currPixel . getBlue ())
        { 
            newPixel = newBg.getPixel(currPixel.getX(), 
                                      currPixel.getY ( ) ) ;
            currPixel . setColor ( newPixel . getColor ( ) ) ;
        } 
    }
}

我想知道是否使用这种条件:

currPixel.getRed() < currPixel.getBlue() && currPixel.getGreen() < 
currPixel.getBlue()

在 if 语句上,它是否有效。换句话说,使用该条件是否具有与currPixel.getRed() + currPixel.getGreen() < currPixel . getBlue ()

4

1 回答 1

1

currPixel.getRed() + currPixel.getGreen() < currPixel.getBlue()将测试蓝色是否大于红色+绿色的总和。因此,如果 RGB 为 10,10,15,则此条件评估为假。

currPixel.getRed() < currPixel.getBlue() && currPixel.getGreen() < currPixel.getBlue()将测试蓝色是否大于红色和蓝色是否大于绿色。因此,如果 RGB 为 10、10、15,则此条件评估为真。

所以不,这两个条件没有相同的效果。(如果在视觉上它们看起来相似,那可能只是巧合的测试结果)

于 2017-11-03T22:18:16.950 回答