The BitmapData class has threshold method which allows to check how many pixels satisfy some condition (e.g. "<=",">","=="); but the method does not appear to work properly when alpha channel in the threshold is in range (0,FF), although it works on the extremes 0 and ff. This code I used for a test:
bd = new BitmapData(16,16,true,0);
var i:int = 0;
var x:int, y:int;
for (var a:uint = 0x0; a<=0xFF; a++){
x = Math.floor(i/16);
y = i - x*16;
// trace(x,y);
var col:uint = combineARGB(a,0xAA,0xBB,0xCC);
trace('set: '+col.toString(16));
bd.setPixel32(x,y,col);
var getP:uint = bd.getPixel32(x,y);
trace('get: '+getP.toString(16));
trace('test threshold at '+getP.toString(16)+': '+bd.threshold(bd,bd.rect, new Point(), "==", getP,getP));
i++;
}
So we create a 16x16 bitmap data and fill it with an ARGB value such as 1AAABBCC to FFAABBCC. AS3 does not set colours to exactly same values as we requested, but to some manipulated version of them. Nevertheless, if we set a pixel, get it and use threshold method to find the value of the pixel, it will only work when the alpha is ff or 0:
set: aabbcc
get: 0
test threshold at 0: 256 // because we initialized all pixels to be 0
set: 1aabbcc
get: 1ffffff
test threshold at 1ffffff: 0
set: feaabbcc
get: feaabbcc
test threshold at feaabbcc: 0
set: ffaabbcc
get: ffaabbcc
test threshold at ffaabbcc: 1
Surely if we can get pixel with getPixel32, then it should be the same with threshold? The rule is as follows:
((pixelValue & mask) operation (threshold & mask))
Mask is 0xFFFFFFFF by default.
trace((0xfeaabbcc & 0xffffffff) == (0xfeaabbcc & 0xffffffff)); // true
Related: post