在Flash中动态导入图像时如何修复所有图像大小?
问题描述:
当我使用闪光灯工作时,我遇到了麻烦,当我处理图像 现在我现在的项目动态上传图像,但这里主要问题是所有的图像尺寸是不同的,当我把图像放入闪光画布每个图像看起来不同的大小意味着确切的图像大小,但我需要所有的图像应该看起来相同的大小在画布上在Flash中动态导入图像时如何修复所有图像大小?
检查图像 如果我改变高度和宽度值,不影响任何地方,这是自动采取固定图像大小但我需要所有的图像看起来确切的大小,我没有得到任何东西
答
我认为我有解决方案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”已完成重新调整。
这可能不是最有效的做事方式,但我认为它适用于您的目的。
http://i.stack.imgur.com/S6xod.jpg – 2015-02-06 05:40:38