Friday, May 29, 2009

Constrain Proportions

Here's a really simple solution that I couldn't figure out for a long time: say you need to downsize an image so that the width changes to 80 pixels. You want to change the height, too, so that the image stays in proportion, but by how much should you change it?

I actually figured out a complex way to calculate the height, but then it hit me that there's a really simple way to do it:

myImage.width = 80;
myImage.scaleY = myImage.scaleX;

No comments:

Post a Comment