I have an image loader that I am attempting to resize dynamically. I would like to make sure that the aspect ratio is kept intact so that the image doesn't stretch. When I reload the image (re-populate it with another image via the loader), there is a resize function that is called. I would like to know what I might be doing wrong with this portion of the resize code:
var aspect:Number = width / height;
var cAspect:Number = _imageBoundary.width / _imageBoundary.height;
if (aspect <= cAspect)
{
_ldr.height = _imageBoundary.height;
_ldr.width = aspect * _ldr.height;
}
else
{
_ldr.width = _imageBoundary.width;
_ldr.height = _ldr.width / aspect;
}
_ldr.x = (_imageBoundary.width - _ldr.width) / 2 + _imageBoundary.x;
_ldr.y = (_imageBoundary.height - _ldr.height) / 2 + _imageBoundary.y;
Any thoughts would be greatly appreciated. I am basing the larger portion of this on bhups's code.
Best