Actionscript 3 掩码参数在BitmapData类的阈值方法中起什么作用?

Actionscript 3 掩码参数在BitmapData类的阈值方法中起什么作用?,actionscript-3,bitmap,bitmapdata,Actionscript 3,Bitmap,Bitmapdata,我正在尝试替换位图中的颜色及其附近的颜色 似乎可行,但似乎必须指定确切的颜色“==”或在确切的颜色“加上”=”之前或之后的所有颜色。我希望mask参数能帮助我找到一种方法,找到一种颜色,以及替换前后的动态颜色范围。它的预期用途是什么 根据下面示例1和2的注释: bit.threshold(bit, bit.rect, point, ">", 0xff000000, 0xffff0000, 0x00FF0000); bit.threshold(bit, bit.rect, point,

我正在尝试替换位图中的颜色及其附近的颜色

似乎可行,但似乎必须指定确切的颜色“==”或在确切的颜色“加上”=”之前或之后的所有颜色。我希望mask参数能帮助我找到一种方法,找到一种颜色,以及替换前后的动态颜色范围。它的预期用途是什么

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

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

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

如果您尝试进行洪水填充,我认为“遮罩”参数对您没有帮助。mask参数允许您忽略测试中的部分颜色。在您的例子中,您希望考虑颜色的所有通道,您只希望匹配是模糊的

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

实现伪代码可能如下所示:

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

您的两个示例都不会产生任何结果,因为掩码将值限制在0x00000000和0x00FF0000之间,然后测试它们是否大于0xFF000000。

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

//_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);
        }
    }
}
/\u快照是位图数据对象

对于(var i:int=0;我可以解释更多吗?你是说如果我将遮罩设置为100%0x00FF0000(红色通道),则忽略没有红色的像素吗?如果我将掩码设置为0x00EE0000会怎么样?我将在主帖子中发布一个示例。不,0x00FF0000将忽略除红色以外的所有内容。0xEE=1110 1110,因此它将忽略其他红色阴影和一些块…这对图像来说真的没有意义。我认为它的用途是过滤整个通道。我感觉我在碰运气但我仍在努力将其付诸实践。你能解释一下以下每一项的作用吗?(在问题中添加了示例)谢谢Michiel(评论不够长)Adden:这让我得到了我想要的,但我仍然想了解参数的作用。抱歉,我周末外出,所以无法回答;)我看到您关于参数的问题已经由Sean回答:)