2015-02-06 34 views
0

當我使用閃光燈工作時,我遇到了麻煩,當我處理圖像 現在我現在的項目動態上傳圖像,但這裏主要問題是所有的圖像尺寸是不同的,當我把圖像放入閃光畫布每個圖像看起來不同的大小意味着確切的圖像大小,但我需要所有的圖像應該看起來相同的大小在畫布上在Flash中動態導入圖像時如何修復所有圖像大小?

檢查圖像 如果我改變高度和寬度值,不影響任何地方,這是自動採取固定圖像大小但我需要所有的圖像看起來確切的大小,我沒有得到任何東西

+0

http://i.stack.imgur.com/S6xod.jpg – 2015-02-06 05:40:38

回答

0

認爲我有解決方案t你的問題。

基本上,您需要創建一個容器(如果您還沒有這樣做)在圖像出現時「保留」圖像或知道圖像的最大高度和寬度。然後,你需要確保寬高比正確

代碼示例(讓你的圖片不會被扭曲。):

var wHRatio:Number=image.width/image.height; //this will give you the width to height ratio to make sure aspect ratio stays the same. 

    if (image.width>mcContainer.width){ //if not using container, enter max width 
     image.width=mcContainer.width; 
     image.height=image.width/wHRatio; 
     // at this point, if the height is still taller than the container, you want to shrink the image again so it's no taller than the container. 
     if (image.height>mcContainer.height){ //if not using container, enter max height 
     image.height=mcContainer.height; 
     image.width=image.height*wHRatio; 
     } 
    } 

****不要忘了你之後「的addChild」已完成重新調整。

這可能不是最有效的做事方式,但我認爲它適用於您的目的。