简体   繁体   中英

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

I need to scale an image with maintaining the aspect ratio in 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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