1
votes

My project loads SWF files using the Loader class, and then loads Sprite objects from those child files. Each sprite has a specific green color, and I want to substitute all pixels of one color for transparent ones.

I can re-compile these Sprites as objects of the BitmapData class, to simplify things, but I'm looking for any way that avoids operating the objects pixel-by-pixel. I'm guessing that I can use some kind of bitmap filter, but I'm just not familiar enough with ActionScript to know specifics.

1
I think that should be possible to do with Pixel Bender shaders - fsbmain
@fsbmain Trying to avoid embedded solutions. - Fuselight
what is your problem with pixel by pixel coloring? you just do this one time, no performance issue occurs - payam_sbr
Oops. Last comment was wrong. I meant that I do it more than once. - Fuselight

1 Answers

3
votes

try threshold with bitmapData of that Sprite.

Before                           After √

enter image description here


var bmd:BitmapData = new BitmapData(sprite.width, sprite.height, true, 0x0);
bmd.draw(sprite);
bmd.threshold(bmd, bmd.rect, new Point(), "==", 0xff00ff00); // 0xff00ff00 = GREEN

you may change the green color, also you are free to setting more range of colours to be transparented, for example, some kind of detecting smooth corners like this:

enter image description here

just need to play with operation argument of threshold, i used "==", but many others available.


refrences :