JPEG-XR Support

AIR 3 includes expanded support for still image file formats. Previous versions of AIR include support for the following image file formats: GIF, JPEG, and PNG – with any other files relying upon external code libraries for interpretation. The recent addition of JPEG-XR (International Standard ISO/IEC 29199-2) brings a new image file format to AIR which boasts more efficient compression than JPG, along with both lossy and lossless compression options. Like the PNG format, JPEG-XR also includes a full alpha channel.

Note

You may be wondering how to generate JPEG-XR files, since many popular tools (including Adobe Photoshop) do not support the export or conversion to .JXR natively. I’ve found the Windows-only tool Paint.NET (http://paint.net/) along with the JPEG XR plugin (http://pdnjpegxrplugin.codeplex.com/) to be most useful in converting images to JPEG-XR.

Many conversion programs actually leave out certain bytes which are necessary for the file to load into the runtime, due to security concerns.

JPEG-XR Support

Figure 2-2. JPEG-XR Support

To load a JPEG-XR file into AIR, you perform the same set of actions that are necessary for any external image to be loaded into a project:

package {
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.ProgressEvent;
    import flash.net.URLRequest;
    import flash.text.TextField;
    import flash.text.TextFormat;

    [SWF(width="600", height="500", backgroundColor="#CCCCCC")]

    public class JPEGXR extends Sprite {

        private var imageLoader:Loader;
        private var traceField:TextField;
        private const JXR_PATH:String = "assets/JPEG-XR.jxr";

        public function JPEGXR() {
            generateDisplayObjects();
        }

        protected function generateDisplayObjects():void {
            imageLoader = new Loader();
            imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
            imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, imageProgress);
            imageLoader.load(new URLRequest(JXR_PATH));
            addChild(imageLoader);

            var defaultFormat:TextFormat = new TextFormat();
            defaultFormat.font = "Arial";
            defaultFormat.size = 22;
            defaultFormat.color = 0xFFFFFF;

            traceField = new TextField();
            traceField.backgroundColor = 0x000000;
            traceField.alpha = 0.6;
            traceField.autoSize = "left";
            traceField.background = true;
            traceField.defaultTextFormat = defaultFormat;
            addChild(traceField);
        }

        protected function imageProgress(e:ProgressEvent):void {
            traceField.appendText(e.bytesLoaded + " / " + e.bytesTotal + " bytes loaded...
");
        }

        protected function imageLoaded(e:Event):void {
            imageLoader.height = stage.stageHeight;
            imageLoader.scaleX = imageLoader.scaleY;

            traceField.text = JXR_PATH + " Loaded!

" + traceField.text;
        }

    }
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset