Schemaphic Systems Blog

Sharing experiences in Flash, Flex and AIR

Extract Bitmap from a MovieClip

with one comment

A code snippet to extract Bitmap from a MovieClip object:

/**
* This returns a Bitmap representation of an area
* of a DIsplayObject from the application.
*
* @param source the DisplayObject whose Bitmap is to be generated
* @param area the rectangular part of the DisplayObject to be considered
* for image creation. The default value is <code>null</code> which denotes

the whole image.
*
* @return A bitmap representation of the DisplayObject maked by a

Rectangular area
*/
static public function getImage( source:DisplayObject, area:Rectangle = null

):Bitmap
{
var bitmapData:BitmapData;
var matrix:Matrix;

if ( area != null ) {

matrix = new Matrix( 1, 0, 0, 1 , Math.abs( area.x ) ,

Math.abs( area.y ) );

if ( area.width > 0 && area.height > 0 )
bitmapData = new BitmapData( area.width, area.height,

true, 0x0 );
else
bitmapData = new BitmapData( source.width,

source.height, true, 0x0 );
} else {

bitmapData = new BitmapData( source.width , source.height ,

true, 0x0 );
}

bitmapData.draw( source, matrix, null, null, area, true );

var bitmap:Bitmap = new Bitmap( bitmapData );
return bitmap;
}

Advertisements

Written by Deepanjan Das

November 30, 2011 at 12:52 PM

Posted in ActionScript3.0, Flash, Flex

One Response

Subscribe to comments with RSS.

  1. Hi, I’m having trouble using your simpleflvwriter script from over here :

    http://www.actionscript.org/resources/articles/1084/1/Screen-capture-with-ActionScript/Page1.html

    I have retrieved the SimpleFlvWriter.as file you have provided and added it to my libraries.

    Then, I have entered the following code on my actions layer :

    import com.adobe.images.JPGEncoder;
    import flash.filesystem.File;
    import flash.filesystem.FileStream;
    import SimpleFlvWriter;

    var count:int = 1;
    var qImageData:BitmapData = new BitmapData(stage.width, stage.height);
    var myFile = new File(“C:/Users/Arno/Documents/Flash work/FLVCreator/Movie.flv”);
    var myWriter:SimpleFlvWriter = SimpleFlvWriter.getInstance();
    myWriter.createFile(myFile, stage.width, stage.height, 24, 0);

    stage.addEventListener(Event.ENTER_FRAME, Capture);

    function Capture(event:Event):void
    {
    //My animation is 240 frames long at 24 fps, so I’m stopping the recording at frame 235
    if(count 0)
    {
    qImageData.draw(stage);
    myWriter.saveFrame(qImageData);
    count ++;
    }
    else if (count >0)
    {
    myWriter.closeFile();
    count = -1;
    trace(“Closed”);
    }
    }

    I receive no errors from flash, and the file is 3 Mbytes big, so it seems to have worked, but when I use flash player to see the results, I have nothing appearing on the screen.

    What did I do wrong ?

    Thanks for your time !

    Arno

    April 20, 2013 at 4:47 PM


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: