views:

25

answers:

2

Let's say I have an Image in Flex, and I want to filter it such that only the Green Pixels are visible...

For example this image:

alt text

Would show up on the screen as:

alt text

How can I accomplish this in Actionscript/Flex?

A: 

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

Robusto
+1  A: 

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.

Juan Pablo Califano