views:

244

answers:

1

Hi all -

I need to find a way to copy a masked bitmap. I have a bitmap on stage, and a user drawn sprite that acts as a mask. I need to capture/copy the masked area bitmap, maintaining the transparency created by the masking to eventually encode as a png.

I could find no documentation on how to accomplish this using copyPixels(), or any other directions.

Thanks in advance for any assistance -

b

+1  A: 

Hello,

I've made a simple test that seems to work:

var square:Sprite = new Sprite();
var circle:Sprite = new Sprite();
var holder:Sprite = new Sprite();

square.graphics.beginFill(0,.5);
square.graphics.drawRect(0,0,100,100);
square.graphics.endFill();

circle.graphics.beginFill(0);
circle.graphics.drawCircle(0,0,50);
circle.graphics.endFill();

addChild(holder);
holder.addChild(square);
holder.addChild(circle);
square.mask = circle;

var cloneData:BitmapData = new BitmapData(holder.width,holder.height,true,0x00FFFFFF);
cloneData.draw(holder);
var clone:Bitmap = new Bitmap(cloneData);
addChild(clone);
clone.x = 30;

I'm creating a BitmapData and using the draw() method to make a clone. The key thing seems to be the last two arguments in the BitmapData constructor. After I pass the holder.width and holder.height, I specify I want the bitmapData to be transparent (true) and have the fill f*ull transparent white (0x00FFFFFF)* in ARGB (alpha-red-green-blue)

Hope this helps :)

George Profenza
Thanks for the assistance, I got pulled away on another project for a short time but will return to accept if I get it working this way...
WillyCornbread
The ARGB info was especially helpful and allowed me to solve my issues. Thanks again for the help!
WillyCornbread
Glad I could help ^_^
George Profenza