AS3 - 将图像缩放到全宽或高度,不会中断

时间:2012-11-21 21:23:35

标签: actionscript-3 scale

我需要在AS3中保持纵横比来缩放图像。它应该缩放到整个舞台大小,但不应该被切断。

怎么做?

谢谢你, 乌利

1 个答案:

答案 0 :(得分:8)

这样的事情应该有效:

// set the scale to fit the width of the image to the width of the stage     
var scale:Number =  stage.stageWidth / myImage.width;

// if the height of the image will be taller than the stage,
// set the scale to fit the height of the image to the height of the stage
if(myImage.height * scale > stage.stageHeight){
    scale = stage.stageHeight / myImage.height;
}   

// apply the scale to the image
myImage.scaleX = myImage.scaleY = scale;