views:

130

answers:

1

We have Bitmap and Bitmapdata objects now. And when using the webcam, we can get raw-pixeldata output from it. But, can we get raw-pixeldata from the "stage" or "swf" object somehow?

I would like to use this to make "small thumbnails" of certain parts of Actionscript applications and these could be complex compositions of dynamic text, bitmap graphics and movieclips at the same time. So it would be nice to make a "quick snap" and just get the current combined pixels into one bitmap and then be able to "save that for later use".

Is that possible? is it too easy? am I just looking the wrong place in the Adobe Docs?

We have images, vectors etc at the same time on stage, so I need to grab the "stage" objects bitmapdata???

+5  A: 

Create a BitmapData and call its draw() method with the corresponding DisplayObject

var bmpData:BitmapData = new BitmapData(sprite.width, sprite.height, true);
bmpData.draw(sprite);

If you want to make thumbnails smaller, create a Matrix and call its createBox method with required scaling parameters and pass it to the draw method.

var bmpData:BitmapData = new BitmapData(thumbW, thumbH, true);
var mat:Matrix = new Matrix();
mat.createBox(thumbW / sprite.width, thumbH / sprite.height);
bmpData.draw(sprite, mat);
Amarghosh
nice! thanks! so logical I almost knew that I must have gotten blind :o) Great! going to try it!
BerggreenDK
Would you mind trying to help me out once more? I will ofcause mark the answer if correct again. My mistake the first time. Sorry about that.
BerggreenDK
What made you unaccept the answer? Did u try `bmpData.draw(stage);`? What happened? Isn't it working?
Amarghosh
No it isn't not when using Stage. Its probarbly me using the wrong object type somehow.public function SaveSnapshot(oCanvas:IBitmapDrawable):void{var snapshot:BitmapData = new BitmapData(oCanvas.width, oCanvas.height, true, 0x00FFFFFF);var cropbox:Rectangle = new Rectangle(0, 0,oCanvas.width,oCanvas.height);snapshot.draw(oCanvas, new Matrix(),null, null, cropbox, false);...}
BerggreenDK
Oooohh... just tried to use "Stage" as objecttype. I have been using a "generic" type of displayobject, to make this snapshot function work with everything including the Stage object.Once I replaced it and wrote "oCanvas:Stage" this worked, I hadnt seen that earlier as the backgrund color from the SWF isnt automatically part of the SWF it seems. Its a minor detail and not important. So I WILL mark this solved again. Sorry about my misunderstanding and once again! THANKS!!! Hope you will try to help me someother time again ;-)
BerggreenDK