简体   繁体   English

加载图像并将宽度和高度更改为3

[英]Load image and change width and height as3

i want to load image from remote url and synchronicity and change it width and height. 我想从远程URL和同步性加载图像并更改其宽度和高度。

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. 我正在使用以下代码,但它要让我更改宽度和高度,我想我需要将加载程序转换为Bitmap对象。

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. 要访问加载程序加载的内容,请使用loader.content参考。 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) . 如果要加载图像,则可以通过(loader.content as Bitmap).bitmapData检索其原始数据,当然,首先要通过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.
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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