Capture image on a Adobe AIR application running on iOS and save to iOS disk

Some of you could ask why this post as it can be achieved using bitmap data and save to camera roll or to app storage using Byte Array?

So to answer if you save bitmap data to camera roll you can not save a reference to that image in your application in case you want to show creations of the user. Only option is to save it in a directory you have access to either in Application Directory or in Document Directory. If you go with that option you have to use byte array to save the image on the disk. It will work fine if you have small images but it wont work well if you have large image or say an image of screen size of iPhone.

So we have write up a very small Native Extension to be used within Flash application. This Native Extension will accept bitmap data and location. It then create image and save it to the location provided. Use it and you will see magically faster image saving in your application.

Here are the swc and ane. Use it in this way

  1. Import swc in your application.
  2. Declare var extension:ScreenShot = new ScreenShot();
  3. If you want to save a jpg file use extension.getScreenShotJPEG( location , quality , bitmapdata );
  4. If you want to save a png file use extension.getScreenShotPNG( location , bitmapdata );

Please refer to this article before deciding a storage location.

You can get the source code from github.

Leave a comment ?


  1. What is the range for quality in getScreenShotJPEG 0-1 or 0-100?
    I found the jpg saved file size is quite large, possible to reduce the file size by setting higher compression level?

    • Range is between 0 to 1. We did not notice about the file size. We will check into that and post update asap.

      • No matter I use 0 or 1, a full screen jpg file size can be around 500-600kb, suppose even with best quality, the jpg file size can be around 100kb.

        This ANE really help me a lot, thank you very much

  2. First of all, great thing! But can’t get it to work. I have added the *.ane
    in flash cs 6 proffesional.
    it throws no error but the image seems not saved in the documents directory.

    my code:

    var jpgSource:BitmapData = new BitmapData(image.width,image.height);

    var extension:ScreenShot = new ScreenShot();

    var file = File.documentsDirectory.resolvePath(“bigimages/”+imageName);
    extension.getScreenShotJPEG( file , 80 , jpgSource );

    am I missing something?


    • Can you please try extension.getScreenShotJPEG( file.nativePath , 80 , jpgSource ); Also the range is between 0-1 so please use that. Thanks

  3. Can this code also be used for storing an image directly into the Camera Roll ?
    I’m looking for an option to store images taken with CameraUI, since CameraRoll.addBitmapData(bitmapData)
    doesn’t seem to send the EXIF data with the bitmapData object, and therefore the orientation information get lost, which can lead to wrongly rotated image stored on the iOS device.

  4. Ok, do you know if there is a way to store a passed BitmapData object into the Camera Roll, taking your ANE as a starting point ?
    For instance using a different directory or a constant that signalizes writeToFile to store the image into the Camera Roll ?

  5. Sameer, don’t know if it works, I just googled for “flash ane saving image” and this is the first link I got:

  6. Hi Sameer,

    thank you very much for sharing this! I have a question: is there some way to listen completion or failure of stored data?


    • Currently that’s not implemented. You can check file exist after the saving call I believe. Thanks

Leave a Comment

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