1 Reply Latest reply on Sep 23, 2009 2:50 PM by Joe ... Ward

    AIR PNG Encoder from Javascript.


      Hi there,


        How can I encode a Bitmap from AIR using the Javascript AIRAliases.js




          var captureFile = air.File.applicationStorageDirectory.resolvePath( 'c:\capture.png' );


          var capture = new air.BitmapData( window.htmlLoader.stage.stageWidth,window.htmlLoader.stage.stageHeight );
          capture.draw( window.htmlLoader );
          var image = new air.Bitmap(capture,"NEVER",false);
          var png = ???



        • 1. Re: AIR PNG Encoder from Javascript.
          Joe ... Ward Level 4

          AIR doesn't have a built-in PNG encoder. If you can find a JavaScript-based encoder you could use that.


          There are ActionScript encoders, including one in the Flex SDK. To use these, you would have to create a SWF that exposed a function to encode the PNG. You would then import that SWF into your application using a script tag.


          The code can be a simple as this:

              import flash.utils.ByteArray;
              import mx.graphics.codec.PNGEncoder;


              public class EncoderUtility
                  public static function encodePNG( bitmapData:BitmapData ):ByteArray
                      var encoder:PNGEncoder = new PNGEncoder();
                      var png:ByteArray = encoder.encode( bitmapData );
                      return png;


          You can compile it with the Flex + AIR SDK using the amxmlc compiler.