Scaling an Image to a Rect
dunbarx at aol.com
dunbarx at aol.com
Tue Oct 15 22:28:42 CEST 2013
So the aspect ratio is to remain constant, that is, the ratio of width to height.
If you want to scale the image, this ratio must be maintained. If the new rect, for example is to be 1,5 times as wide as the old, but the new height is only 1,4 times as tall as the old, then the larger (width) value has to be used for both, and the excess height cropped. Similarly, if the image is scaled down, the larger value is to be "filled", and the other cropped. In all cases, the ratio is maintained.
Using the several properties, "width", "height", "rect", "topLeft", etc, can you manage this? Write back if not, but it will be a terrific exercise for learning, and you should try first.
From: Dan Friedman <dan at clearvisiontech.com>
To: use-livecode <use-livecode at lists.runrev.com>
Sent: Tue, Oct 15, 2013 4:11 pm
Subject: Scaling an Image to a Rect
I have been piddling around with this for weeks and still can't get it right. I
kinda got it working... but it's still not always 100% correct. So, I thought I
would ask this list for assistance since most of the people here are far smarter
You have a rect and an image. The goal is to completely fill the rect with the
image. But, we don't want to distort the image. So, you need to proportionally
scale the image up (if the image is smaller than the rect) or down (if the image
is larger than the rect). Remember that we want to completely fill rect. It's
ok (and expected) that some of the image will be cropped.
Think of this as setting the background of a stack with an image. You want to
fill the entire background of the stack (regardless of the size of the stack),
with the image (regardless of the rect of the image). But we don't want to
distort the image.
use-livecode mailing list
use-livecode at lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription
More information about the use-livecode