tags:

views:

332

answers:

3

Currently i'm using SWFToImage to convert my charts dynamically generated in a swf to an image. But it crashes a lot when several images need to be created at the same time.

Are there better solutions available to generate an image from an SWF file?

A: 

You might want to consider a non-flash chart generator if you're getting rid of the flash to just use an image. It would be much faster/efficient/reliable.

Disregard this if the flash is actually used by someone.

Ben S
A: 

Depending on whether you're able to modify the source of the SWF, you could on, say, the click of a button, create a BitmapData object from the stage contents and then encode that data into an image format. You'd then use AIR to save it to the desktop or a server side language to save it to a server, again depending on your requirements. I can elaborate further if this direction sounds reasonable.

Reply to comment: Yes, you're right, you could easily do it loading the external SWF as well.

The following is a rough outline of what you need to do:

Loading the external SWF is as simple as this:

var loader:Loader = new Loader();

var urlRequest:URLRequest = new URLRequest("url-to-external.swf");

loader.load(urlRequest);

Then copy the external SWF content into a BitmapData object (perhaps on some event, like the click of a button):

var bitmapData:BitmapData = new BitmapData(loader.width, loader.height); bitmapData.draw(loader);

However, it may require some extra work depending on what your source SWF looks like. You may especially need to take the (x,y) coordinates of the contents within the loaded SWF into account as they may create an offset of what is drawn to the BitmapData object.

You can then use the BitmapData object to create an image file, say a PNG, using the PNGEncoder class from the AS3 core lib: http://code.google.com/p/as3corelib/

Stiggler
This sounds interesting, but I can't modify the SWF. Isn't it possible to load that swf into the memory and then create an BitmapData object of that swf?
ToRrEs
A: 

@Stiggler

This sounds interesting, but I can't modify the SWF. Isn't it possible to load that swf into the memory and then create an BitmapData object of that swf?

Here's a site that explains how to load an external swf.

ToRrEs