简体   繁体   中英

Load image and change width and height as3

i want to load image from remote url and synchronicity and change it width and height.

i am using the folowwing code, but it want let me change the width and highet, i think i needto convert the loader to a Bitmap object.

how can i do that, thank you very much.

var imageURLRequest:URLRequest = new URLRequest(pic); 
var myImageLoader:Loader = new Loader(); 
myImageLoader.load(imageURLRequest); 
var urlRequest:URLRequest = new URLRequest(pic);
var loader:Loader = new Loader();
loader.load(urlRequest);
trace(loader.width); // return 0
loader.width =100; //dosent work
allMC[i].img.addChild(loader);

To access what the loader loaded, use loader.content reference. If you are loading an image, you can retrieve its raw data via (loader.content as Bitmap).bitmapData , of course first check if it's so via if (loader.content is Bitmap) . Also, you need to do all of this after your loader will finish loading, it'll send an event indicating this.

...
loader.load(urlRequest);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderComplete);
...
private function loaderComplete(e:Event):void {
    // now your image is fully loaded
    trace(loader.content.width);
    // etc etc, whatever you need to do with your image prior to 
    // addressing it from elsewhere.
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM