获取 Spark 图像的缩放图像尺寸

3

是否有类似于spark图片的contentWidth和contentHeight的属性?

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

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

非常感谢您的帮助。

2个回答

2

我刚试图解决这个确切的问题。我发现一个足够好的解决方案是使用IMAGE_ID.transform.pixelBounds.height(或宽度)。请注意,直到图像的updateComplete事件触发后,此属性才会设置。不知为何FLEX没有一个简单的scaledWidth属性。


1

尝试扩展Spark Image组件,包括2个新的只读属性,以提供缩放宽度和高度,作为contentWidthcontentHeight的等效。

以下将创建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;
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接