mask参数在BitmapData类的阈值方法中做了什么?

时间:2011-08-18 05:30:11

标签: actionscript-3 bitmap bitmapdata

我正在尝试在位图中替换它附近的颜色和颜色。

threshold()似乎有效,但似乎必须在确切颜色“<”之前或之后指定确切的颜色“==”或所有颜色&安培; “>” 中加上“< =”和“> =”。我希望mask参数能帮助我找到一种方法,在它被替换之前和之后找到颜色和动态范围的颜色。它的用途是什么?

根据以下示例1和2中的注释:

bit.threshold(bit, bit.rect, point, ">", 0xff000000, 0xffff0000, 0x00FF0000); 

bit.threshold(bit, bit.rect, point, ">", 0xff000000, 0xffff0000, 0x00EE0000);

2 个答案:

答案 0 :(得分:1)

如果您尝试进行洪水填充,我认为mask参数不会对您有所帮助。 mask参数允许您忽略测试中的部分颜色。在您的情况下,您想要考虑颜色的所有通道,您只希望匹配模糊。

e.g。如果要替换红色分量为0的所有像素,可以将掩码设置为0x00FF0000,因此它将忽略其他通道。

实现伪代码可能看起来像这样:

input = readPixel()
value = input & mask
if(value operation threshold)
{
    writePixel(color)
}

由于掩码将值限制在0x00000000和0x00FF0000之间,然后测试它们是否大于0xFF000000。

答案 1 :(得分:1)

我也做到了这一点,最终,我发现最好创建自己的阈值方法。你可以在下面找到它。一切都在评论中解释。

//_snapshot is a bitmapData-object
for(var i:int = 0; i <= _snapshot.width; i++)
{
    for(var j:int = 0; j <= _snapshot.height; j++)
    {
        //We get the color of the current pixel.
        var _color:uint = _snapshot.getPixel(i, j);                     

        //If the color of the selected pixel is between certain values set by the user, 
        //set the filtered pixel data to green. 
        //Threshold is a number (can be quite high, up to 50000) to look for adjacent colors in the colorspace.
        //_colorToCompare is the color you want to look for.
        if((_colorToCompare - (100 * _threshold)) <= _color && _color <= (_colorToCompare + (100 * _threshold)))
        {
            //This sets the pixel value.
            _snapshot.setPixel(i, j, 0x00ff00);
        }
        else
        {
            //If the pixel color is not within the desired range, set it's value to black.
            _snapshot.setPixel(i, j, 0x000000);
        }
    }
}
相关问题