AS3: bitmapdata threshold example
[ 2010-08-10 14:30:00 | Author: liuhuan ]
Is there any magic wand tool we can use in Flash? ActionScript 3 provides us a method called threshold. Codes below:
function applyThreshold(mc:MovieClip) {
var NewBitmpapData:BitmapData = new BitmapData(mc.width, mc.height, true, 0);
NewBitmpapData.draw(mc);
var pt:Point = new Point(0, 0);
var NewRect:Rectangle = new Rectangle(0, 0, mc.width, mc.height);
NewBitmpapData.threshold(NewBitmpapData, NewRect, pt, ">=", 0xFFCCCCCC, 0x00000000, 0xFFFFFFFF, false);
var bm:Bitmap = new Bitmap(NewBitmpapData);
this.addChild(bm);
bm.x = mc.width;
}
applyThreshold(mUmbrella);
var NewBitmpapData:BitmapData = new BitmapData(mc.width, mc.height, true, 0);
NewBitmpapData.draw(mc);
var pt:Point = new Point(0, 0);
var NewRect:Rectangle = new Rectangle(0, 0, mc.width, mc.height);
NewBitmpapData.threshold(NewBitmpapData, NewRect, pt, ">=", 0xFFCCCCCC, 0x00000000, 0xFFFFFFFF, false);
var bm:Bitmap = new Bitmap(NewBitmpapData);
this.addChild(bm);
bm.x = mc.width;
}
applyThreshold(mUmbrella);
The codes added a threshold to bitmapdata, sets pixels with RGB value smaller than #CCCCCC to be transparent.
[Last Modified By liuhuan, at 2010-08-10 14:29:46]

There is no comment on this article.
You can't post comment on this article.