PDA

View Full Version : Bitmap grab of lower layers? Image transformations of stage?



tim0123
July 20th, 2009, 05:24 PM
Hi,

I'm trying to do something which I'm not sure is possible in AS3. If anyone has any answers/suggestions I'd love to hear them. Thanks!

Basically, I have a number of display objects drawing to the stage, including bitmaps, graphics/shapes, and text. What I want to do is put a layer on top of this that "grabs" or copies the image resulting from all the rendered objects below it.

That is, I want to get a bitmap object that contains an image of the all the rendered objects beneath it in the display list. Consider it as taking a screen grab of the stage.

The ultimate goal is to be able to then apply transformations on this bitmap, giving the appearance of transforming all the objects that draw under it.

Is there a way to get such a bitmap? Or if not, is there a way to apply an image transformation (e.g. rotation, etc.) to the stage after a bunch of objects are drawn onto it?

Note: I am programming AS3 directly and compiling with the Flex command line tools; I don't have the Flash development environment.

Thanks!

- Tim

senocular
July 20th, 2009, 05:32 PM
You can only capture a single display object (with its children) as a bitmap at a time. Now, with that in mind, there's nothing stopping you from capturing a parent display object after temporarily hiding (visible=false) all display objects above a target display object in the display list.

tim0123
July 20th, 2009, 05:38 PM
Hmm ... that sounds like it should handle what I need.

Follow up question: How does one capture a single display object as a bitmap? :-) The closest thing I could find was to use cacheAsBitmap, however I couldn't see how to actually get a copy of the internal bitmap image in this case.

Thanks!

- Tim

senocular
July 20th, 2009, 05:40 PM
BitmapData.draw(targetDisplayObject)

I was never a big fan of the naming of that method, but what it's doing is drawing what you pass into it (targetDisplayObject) into the BitmapData instance.

tim0123
July 20th, 2009, 05:42 PM
Cool, I'll give it a try. Thanks.

- Tim

creatify
July 20th, 2009, 05:43 PM
I think this would/should work?



var _bmpd:BitmapData = new BitmapData(stage.stageWidth,stage.stageWidth,true, 0xFFFFFF);
var _bmp:Bitmap = new Bitmap(_bmpd);

_bmpd.draw(MovieClip(root));

addChild(_bmp);

tim0123
July 20th, 2009, 05:58 PM
That did the trick! Thanks.

- Tim