开发者

Filtering out all but a specific color of an image in Flex

Let's say I have an Image in Flex, and I want to filter it such that only the Green Pixel开发者_如何学编程s are visible...

For example this image:

alt text http://www.LiquidFeline.com/Images/Circles.png

Would show up on the screen as:

alt text http://www.LiquidFeline.com/Images/Circles2.png

How can I accomplish this in Actionscript/Flex?


You can do this easily with the threshold method of the BitmapaData class.

Basically, make a copy of the image. Then make every pixel that fails to pass the threshold test fully transparent. The test in this case could be pixel != your shade of green.

Sample code:

var color:uint = 0xff22b14c;
var bmd:BitmapData = new BitmapData(image.width,image.height,true);
bmd.draw(image);
bmd.threshold(bmd,new Rectangle(0,0,image.width,image.height),new Point(0,0),"!=",color,0,0xffffffff);
addChild(new Bitmap(bmd));

With a bit more of work you could isolate ranges of colors, but for a solid color as in your case, this should do it.


You can try applying chromakey effects the Bitmap and BitmapData classes. See a tutorial at http://cnx.org/content/m34463/latest/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜