Based on my previous tutorial on how to save a Jpeg image from a DisplayObject, I’m releasing an helper class to do the same thing with a couple of lines of code.
The class SaveToBitmap.as allow you to save any drawable DisplayObject to JPG and PNG format as well.
The usage is pretty straightforward; simply put the unzipped folder in you CLASSPATH folder and write this lines of code in the ActionScript panel in Flash CS3/CS4 or Flex:
import maja.air.SaveToBitmap
var save:SaveToBitmap = new SaveToBitmap( myDisplayObject )
// optional quality parameter, default: 100
save.jpgQuality = 80
// the default format is JPG, you can specify to save in PNG by using this setting:
save.format = SaveToBitmap.PNG
[/code]
The class needs the As3CoreLib library to work properly.
Keep in mind this class works for Air project only since it uses the FileStream object to perform the save. I will release a swf version soon.
Download it: [download id="5"]
Thanks for this helper class. Do you think it is possible to save a loaded 24-bit PNG (with alpha channel) as a SWF but compressed as a JPG? Similar to the Flash IDE whereby you can import PNGs into the library but compress them as JPG for playback.
Thanks-
cf
Hi,
Thank you for your great class.
However, your license is quite restrictive (@copy 2009 http://www.fmajakovskij.info with no permission to use commercially or otherwise).
I would like to use this in a client’s commercial product. Is there anyway you could add a MIT or BSD license, or give permission to copy it?
Thank your either way for the great example.
It wasn’t my intention to limit its usage.
Use it as it were released under MIT license.
Regards
This is lightning fast! Thanks for posting it.
How do you know when the image is completely saved? I have multiple images to load and save. Is there a ‘save completed’ event that I can then proceed to load my next image?
Sounds great but the download link doesn’t seem to be working?