开发者

large image loading problem

I had tired loading an image form a url below is my sample code , when tried to load a large image which is greater than 8191 pixel in width or height the Event.COMPLETE is not dispatched , i am aware of the flash player 10 BitmapData limit ,so cant we load an image greater than this 8191 pixel limit ?is there any workaround for this Or any other method you suggest in doing ?

 private function loadImage(url:String):void
                            {
                                var request:URLRequest = new URLRequest(url);               
                                var imageLoader:Loader = new Loader();              
        开发者_如何学C                        var context:LoaderContext;
                                context = new LoaderContext();
                                context.checkPolicyFile = true; 
                                imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, image_completeHandler);      
                                imageLoader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

                                imageLoader.load(request,context);
                            }

            private function image_completeHandler(event:Event):void
            {
                   trace(" Image load Complete");
            }

            private function ioErrorHandler(event:IOErrorEvent):void 
            {
            trace("ioErrorHandler: " + event);
         }


I would recommend that you split up the images. If you need Flash to handle the images as one (moving, scaling) I would write a holder-class that adds the image pieces as children of the itself.

I added some code and a link to a test below. Look at the code in action here. (wait for the SWF to load).

//TestClass

package
{
    import com.kazumakzak.display.TileImage;

    import flash.display.Sprite;
    import flash.events.Event;

    public class TestBigImage extends Sprite
    {

        [Embed(source="assets/piece.png")]
        private var imageClass : Class;

        private var _image : TileImage;
        private var _counter : Number = 0;

        public function TestBigImage()
        {
            // create image with tile size 640x480
            _image = new TileImage(640, 480);

            // add tiles at positions 
            _image.addTile(new imageClass(), 1, 1);
            _image.addTile(new imageClass(), 1, 2);
            _image.addTile(new imageClass(), 2, 1);
            _image.addTile(new imageClass(), 2, 2);
            _image.addTile(new imageClass(), 3, 1);
            _image.addTile(new imageClass(), 3, 2);

            // add to display list
            addChild(_image);


            addEventListener(Event.ENTER_FRAME, render);
        }

        private function render(event : Event) : void
        {
            _counter += 0.05;
            _image.x = -640 + Math.cos(_counter) * 640
        }
    }
}

//TileImage.as

package com.kazumakzak.display
{
    import flash.display.Bitmap;
    import flash.display.Sprite;

    public class TileImage extends Sprite
    {

        private var _tileWidth : int;
        private var _tileHeight : int;

        public function TileImage(tileWidth : int, tileHeight : Number)
        {
            _tileWidth = tileWidth;
            _tileHeight = tileHeight;
        }

        public function addTile(source : Bitmap, tileX : int, tileY : int) : void
        {
            source.x = (tileX-1) * _tileWidth;
            source.y = (tileY-1) * _tileHeight;

            addChild(source);
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜