how to create a '.png' image from a flash object

356 views Asked by At

how to create a '.png' image from a flash object.

Currently I am using 'OpenFlashChart' in my application, which works good and shows me a flash of bar or pie chart, now what i want to do is the store a '.png' image of this chart in a folder.

NOTE : I have removed the 'ofc_upload_image.php' file from this library as it has certain vulneribilities. So, basically what i want is to convert a flash into a '.png' image.

Thanks in advance

1

There are 1 answers

0
jayrobin On

Taking a screenshot in a SWF and encoding it is fairly straightforward:

var screen:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight);
screen.Draw(stage, null, null, null, new Rectangle(0, 0, stage.stageWidth, stage.stageHeight));

var encoder:PNGEncoder = new PNGEncoder();
var png:ByteArray = encoder.encode(screen);

You can replace the Rectangle params as necessary to capture only a certain portion (e.g. your chart).

I'm going to assume you are wanting to upload the image to your server, in which case you can use a URLLoader to send the byte array containing the encoded PNG data:

var request:URLRequest = new URLRequest(YOUR_URL);
request.contentType = "application/octet-stream";
request.method = URLRequestMethod.POST;
request.data = png;

var loader:URLLoader = new URLLoader();
loader.load(request);