加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flex 中获得图片的原始大小

发布时间:2020-12-15 01:17:22 所属栏目:百科 来源:网络整理
导读:在Flex中加载image的过程中,是无法获得image大小的。例如: var img:Image = new Image();img.source = "images/example.jpg";trace(img.height);trace(img.width);trace(img.contentHeight);trace(img.contentWidth);结果都是零,因为image并没有加载完成

在Flex中加载image的过程中,是无法获得image大小的。例如:

var img:Image = new Image();
img.source = "images/example.jpg";
trace(img.height);
trace(img.width);
trace(img.contentHeight);
trace(img.contentWidth);

结果都是零,因为image并没有加载完成。
解决方法是添加监听事件,在加载完成后再去获取图像的大小就可以了。

var loader:Loader = new Loader()
loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onIconLoadComplete);
loader.load(new URLRequest(imgUrl));       
private function onIconLoadComplete(event:Event):void{
                
   trace(event.currentTarget.width);
   trace(event.currentTarget.height);
                        
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读