• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Possibly stupid question

New Here ,
Jul 30, 2008 Jul 30, 2008

Copy link to clipboard

Copied

I can't find resources related to this anywhere I look, though it's possible I'm not looking correctly... Anyway, what I want to do is capture everything on the stage as a bitmap so that I can manipulate the bitmap data. The content on the stage is mostly/all vector based. Here's the code I have so far:

var myBitmapData:BitmapData = new BitmapData(stage.width,stage.height);
myBitmapData.draw(stage);

Pretty strait-forward. However, the pixel data isn't coming through. Is there a way to convert the vector data into pixel data sot hat this will work? Is there some un-documented feature that does all this already?

Any help you can offer, is greatly appreciated!
-Thomas
TOPICS
ActionScript

Views

554

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 30, 2008 Jul 30, 2008

Copy link to clipboard

Copied

Thomas,

> I'm not looking correctly... Anyway, what I want to do is capture
> everything on the stage as a bitmap so that I can manipulate the
> bitmap data.
...
> var myBitmapData:BitmapData = new BitmapData(stage.width,stage.height);
> myBitmapData.draw(stage);

Not a stupid question. In fact, you're almost there. 🙂 You need a
Bitmap instance to use in cahoots with your BitmapData instance. Here's a
quick bit if sample code:

var bmpData:BitmapData = new BitmapData(stage.stageWidth,
stage.stageHeight);
bmpData.draw(stage);
var bmp:Bitmap = new Bitmap(bmpData);

var spr:Sprite = new Sprite();
spr.addChild(bmp);
addChild(spr);

spr.addEventListener(Event.ENTER_FRAME, frameHandler);
function frameHandler(evt:Event):void {
spr.y++;
}

I've created the BitmapData instance first, and have fed it the width
and height of the Stage. (Note: this differs from yours, because yours
samples from the whole stage, but only accounts for the width and height of
the area that contains content. That may or may be what you want. My
version takes its width and height from the whole Stage, content or not.)

Next, the BitmapData intance uses its draw() method to sample pixels
from the Stage.

After that, a new Bitmap instance takes the BitmapData instance as its
seed material. Now you have a bona fide bitmap. You'll need to add it to
the display list in order to see it, so in my expample I've created a Sprite
instance and added the bitmap to the sprite's display list. In turn, the
sprite is added to the display list of the main timeline, otherwise the
bitmap doesn't get seen. Make sense, right?

Finally, just for kicks, I gave the sprite a simple animation, just so
you can see it take its snapshot, then move out of the way ... to verify
that it indeed captures the whole Stage.


David Stiller
Co-author, Foundation Flash CS3 for Designers
http://tinyurl.com/2k29mj
"Luck is the residue of good design."


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 31, 2008 Jul 31, 2008

Copy link to clipboard

Copied

Thank you so much! That has solved all my problems (well, relating to flash, anyway... 😉 )

-Thomas

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 23, 2016 Sep 23, 2016

Copy link to clipboard

Copied

This thread is from so long ago, but it deals with my issue so I'm resurrecting it.

I'm using flash cc.  I want a screen capture of the stage.   I've input the above code into the frame which I want captured.  The code appears to work. I can even see the little animation showing that the screen has, indeed, been captured.  But then I can't find the bit map.  It doesn't appear in the time line, nor the library, nor the folder where the .fla is stored.

What am I missing?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Sep 30, 2016 Sep 30, 2016

Copy link to clipboard

Copied

You're not missing anything actually - the bitmap in question is created at runtime, and then is disposed of when you press stop. If you want to save the capture to a file you can do that - just Google 'as3 save bitmapdata file' and you should find a lot.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 01, 2016 Oct 01, 2016

Copy link to clipboard

Copied

LATEST

Ok thanks Dmennenoh.  I had the impression that the AS in question would automatically save the captured bitmap as a usable jpeg in the library (which is what I wanted). In the "modify" menu there is an option to "convert to bitmap" whatever is selected on the stage which does automatically produce a usable image in the library (which is also generically titled "bitmap") so I think that's where my confusion came in.    Thanks for clarifying that there are some extra steps to achieve that goal with the AS.   I'll research it.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines