Chapter 2. External Image Capabilities

Taking into account the close relationship between AIR and Flash Player, along with Flash Player’s focused ability to readily handle vector drawing objects, it is often overlooked how capable the Flash Platform is at utilizing bitmap data through embedded or external image files. Whether using PNG, JPG, GIF, or the new JPEG-XR filetype, there is no denying that this imaging technology is extended and improved upon in some rather spectacular ways.

Enhanced High-Resolution Bitmap Support

Loaded BitmapData objects have historically been limited to 8,191 total pixels along any side with a total supported resolution of 16,777,215 pixels…which isn’t a whole lot when dealing with high resolution images. With the megapixel count of consumer digital cameras breaking well past 10, the need for greater resolution is easily apparent. With AIR 3, these restrictions have been lifted, making this is a feature that can be leveraged through a multitude of project types.

Note

1 megapixel is equal to 1,000,000 pixels.

AIR 2 supports up to 16.777 megapixels.

AIR 3 incudes no such restrictions.

High-resolution bitmap

Figure 2-1. High-resolution bitmap

We don’t actually need to do anything to enable support for this behavior, as it is built into the AIR runtime itself. In the following example, we’ll use the Loader class to bring a high-resolution image into an AIR project:

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

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

    public class HighRes extends Sprite {

        private var imageLoader:Loader;
        private var traceField:TextField;

        public function HighRes() {
            generateDisplayObjects();
        }

        protected function generateDisplayObjects():void {
            imageLoader = new Loader();
            imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
            imageLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, imageProgress);
            imageLoader.load(new URLRequest("assets/highres.jpg"));
            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 = "Loaded image is " + e.target.width + " x " + e.target.height + " pixels =>
That's " + e.target.width*e.target.height + " total pixels!

" + traceField.text;
        }

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

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