Monday, June 18, 2012

[Action Script] Remove transparency from BitmapData June,2012

I'm trying to create a metaballs effect with AS3. All of the tutorials I've looked at showed good working examples but I didn't really understand how they got there.
I have lots of circles to which I apply a glow effect when they are created. The circles have a color of 0xFF00FF00 (solid green) and the glow is also green. I add these circles to a movieclip called metaballContainer. I also have a variable called screenshot that is a Bitmap. The screenshot is added to the stage at the beginning and is used to show the effect of the threshold.
I then call up this code every frame:
ActionScript Code: var bitmapData:BitmapData = new BitmapData(stage.stageWidth,stage.stageHeight);bitmapData.draw(metaballContainer);bitmapData.threshold(bitmapData, bitmapData.rect, new Point(), "<", 0xFF00FF00, 0xFF00FF00);screenshot.bitmapData = bitmapData;First I create a new BitmapData called bitmapData that fills the entire stage. I then draw a the metaballContainer (and hence all of the metaballs). to the bitmapData. I then apply the threshold. Finally, the screenshot is updated by changing the bitmapData of the screenshot to the new data.

The problem is with the threshold:
ActionScript Code: bitmapData.threshold(bitmapData, bitmapData.rect, new Point(), "<", 0xFF00FF00, 0xFF00FF00);What I expected to happen was that all pixels with a color value less than 0xFF00FF00 would have their values changed to 0xFF00FF00. Since the only color I am using is green, I expected all greens wit different transparencies less than opaque to become opaque.
0xEE00FF00
0xDF00FF00
0xA600FF00
0x6G00FF00
To just become 0xFF00FF00 (solid green)

But it doesn't work like this. I think I need to do something with the fill color for the BitmapData. At the minute, by default, it is set to transparent white. But why do I need to specify the whether or not the background is transparent? Doesn't the ARGB fill color already say how transparent something is? I think I might need to use a mask but am unsure how one works or what it does.

Thank you for reading this and I appreciate any feedback you may have.
Remove transparency from BitmapData

Related Post



0 comments: