Adobe Air: Save to JPG and PNG helper class

December 2, 2009 by fMajakovskij

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"]

5 thoughts on “Adobe Air: Save to JPG and PNG helper class

  1. cf says:

    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

  2. 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.

  3. gavin says:

    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?

  4. Tim says:

    Sounds great but the download link doesn’t seem to be working?

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>