Image 获取spark图像的缩放图像尺寸

Image 获取spark图像的缩放图像尺寸,image,flex4,Image,Flex4,对于spark图像,是否存在与contentWidth和contentHeight等效的值 我可以获得图像组件本身的大小,以及sourceWidth和sourceHeight属性,以获得图像的未缩放大小 但我无法计算出图像组件中显示的源的缩放图像宽度和高度 /** * Returns the width of the image display taking into account the actual * constraints of the container. If no sca

对于spark图像,是否存在与contentWidth和contentHeight等效的值

我可以获得图像组件本身的大小,以及sourceWidth和sourceHeight属性,以获得图像的未缩放大小

但我无法计算出图像组件中显示的源的缩放图像宽度和高度

/**
 * 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;
}

非常感谢您的帮助。

尝试扩展Spark
图像
组件,使其包含两个新的只读属性,以提供与
内容宽度
内容高度
等效的缩放宽度和高度

以下内容将创建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;
}
/**
*返回图像显示的宽度,并考虑实际宽度
*容器的约束。如果未发生缩放,则实际
*返回控件的宽度。
*/ 
[可绑定(event=“scaledWidthChanged”)]
公共函数get scaledWidth():Number
{
var num:Number=this.width;
如果(scaleMode==“信箱”)
{
尝试
{
如果((宽度>0)和&(源宽度<源高度))
{
num=(sourceWidth/sourceHeight)*宽度;
}                   
}
捕获(e:错误)
{
num=此宽度;
}
}
返回num;
}
/**
*返回图像显示的高度,并考虑实际的
*容器的约束。如果未发生缩放,则实际
*返回控件的高度。
*/ 
[Bindable(event=“scaledHeightChanged”)]
公共函数get scaledHeight():编号
{
var num:Number=this.width;
如果(scaleMode==“信箱”)
{
尝试
{
如果((高度>0)和&(源高度<源宽度))
{
num=(sourceHeight/sourceWidth)*高度;
}                   
}
捕获(e:错误)
{
num=这个高度;
}
}
返回num;
}

只是想解决这个问题。我找到的一个合适的解决方案是使用
IMAGE\u ID.transform.pixelBounds.height
(或width)。请注意,只有在为图像触发
updateComplete
事件后,才会设置此选项。不知道为什么FLEX没有简单的scaledWidth属性