簡體   English   中英

加載圖像並將寬度和高度更改為3

[英]Load image and change width and height as3

我想從遠程URL和同步性加載圖像並更改其寬度和高度。

我正在使用以下代碼,但它要讓我更改寬度和高度,我想我需要將加載程序轉換為Bitmap對象。

我該怎么辦,非常感謝。

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);

要訪問加載程序加載的內容,請使用loader.content參考。 如果要加載圖像,則可以通過(loader.content as Bitmap).bitmapData檢索其原始數據,當然,首先要通過if (loader.content is Bitmap)來檢查其原始數據。 另外,您需要在加載程序完成加載后執行所有這些操作,它會發送一個指示此事件的事件。

...
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