Oct
10
2010

 

In order to create images, you need to access the pixel data of the MovieClip object. The data can be obtained by rendering a MovieClip into a BitmapData object and using this data, you can write your own encoder to convert it to any image format you’d like. Writing such encoder is not a trivial task and requires understanding of the image format algorithm, or you can use pre-written libraries.
You can download the PNGEncoder and JPGEncoder , which is part of as3corelib, an open source project library from:
http://github.com/mikechambers/as3corelib/tree/master/src/com/adobe/images/

 

The library allows you to convert MovieClip to either JPG or PNG format, which you can then use to send into external script for saving or uploading. An example is shown below:

[c]
	import com.adobe.images.JPGEncoder;

	var bitmapData:BitmapData=new BitmapData(mc_canvas.width, mc_canvas.height);
	bitmapData.draw(mc_canvas);  
	//
	var jpgEncoder:JPGEncoder = new JPGEncoder(90);
	var byteArray:ByteArray = jpgEncoder.encode(bitmapData);

	byteArray = PNGEncoder.encode(bitmapData);
[/c]

In the example, mc_canvas if your MovieClip and the byteArray is the bitmap data which in this example is encoded in JPG format (the process is very similar with PNG). You can then send this data to external script, such as PHP to save it as a JPG file.

 

You can check a working example and source code here:
http://www.permadi.com/blog/2011/02/flash-as3-saving-image-to-disk/

Comments are closed.