火花圖像是否有與contentWidth和contentHeight等效的內容?獲取火花圖像的縮放圖像維度
我可以得到圖像組件本身的大小,以及sourceWidth和sourceHeight屬性來獲取圖像的未縮放大小。
但我無法計算圖像組件中顯示的縮放圖像的寬度和高度。
任何幫助極大的讚賞。
火花圖像是否有與contentWidth和contentHeight等效的內容?獲取火花圖像的縮放圖像維度
我可以得到圖像組件本身的大小,以及sourceWidth和sourceHeight屬性來獲取圖像的未縮放大小。
但我無法計算圖像組件中顯示的縮放圖像的寬度和高度。
任何幫助極大的讚賞。
嘗試延伸的火花Image
組件包括2個新的只讀屬性,以提供縮放的寬度和高度作爲相當於contentWidth
和contentHeight
。
以下將創建2個新的可綁定屬性,以返回Spark Image
組件內顯示的圖像的實際縮放寬度和高度。
/**
* Returns the width of the image display taking into account the actual
* constraints of the container. If no scaling has occurred the actual
* width of the control is returned.
*/
[Bindable(event="scaledWidthChanged")]
public function get scaledWidth():Number
{
var num:Number = this.width;
if (scaleMode == "letterbox")
{
try
{
if ((width > 0) && (sourceWidth < sourceHeight))
{
num = (sourceWidth/sourceHeight) * width;
}
}
catch(e:Error)
{
num = this.width;
}
}
return num;
}
/**
* Returns the height of the image display taking into account the actual
* constraints of the container. If no scaling has occurred the actual
* height of the control is returned.
*/
[Bindable(event="scaledHeightChanged")]
public function get scaledHeight():Number
{
var num:Number = this.width;
if (scaleMode == "letterbox")
{
try
{
if ((height > 0) && (sourceHeight < sourceWidth))
{
num = (sourceHeight/sourceWidth) * height;
}
}
catch(e:Error)
{
num = this.height;
}
}
return num;
}
只是試圖解決這個確切的問題。我找到的適當解決方案是使用IMAGE_ID.transform.pixelBounds.height
(或寬度)。請注意,此事件將在updateComplete
事件觸發圖像之後纔會設置。不知道爲什麼FLEX沒有簡單的scaledWidth屬性。