简体   繁体   English

AS3-将图片缩放至全宽或全高而不会裁切

[英]AS3 - Scale image to full width or height without cut off

I need to scale an image with maintaining the aspect ratio in AS3. 我需要在AS3中保持高宽比的情况下缩放图像。 It should be scaled to the full stage size but nothing should be cut off. 它应按比例缩放到整个舞台大小,但任何内容都不应删减。

How to do it? 怎么做?

Thank you, Uli 谢谢你乌里

Something like this should work: 这样的事情应该起作用:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM