ImageEn, unit hyieutils



function IEAdjustRectToAspectRatio(InRect : TRect;
                                   ImgWidth, ImgHeight: Integer;
                                   DisplayWidth, DisplayHeight : Integer;
                                   FitMethod: TFitMethod = _fmFitWithinRect ) : TRect;


Adjusts the past rect so that it matches the aspect ratio of an image. For example, if InRect specifies a selected area where you want to draw an image, you can adjust the selection so that the image is not stretched (maintains its aspect ratio).

Parameter Description
InRect The source rect (to be adjusted)
ImgWidth, ImgHeight The dimensions of the image (to which inRect will be adjusted)
DisplayWidth, DisplayHeight The maximum width/height for the rect (typically the client area of a display control, such as a TImageEnView)
FitMethod Rather than reducing the area of InRect, it is increased. The returned rect will cover the entire passed rect

Assuming InRect does not already match the ratio of ImgWidth/ImgHeight then IEAdjustRectToAspectRatio will return a rect with either:
 Left and Right unchanged but Top increased and Bottom decreased
 Top and Bottom unchanged but Left increased and Right decreased

But if FitMethod is _fmFillRect_WithOverlap then result wil be either:
 Left and Right unchanged but Top decreased and Bottom increased
 Top and Bottom unchanged but Left decreased and Right increased

Compatibility Notes

This is the same as the AdjustRectToAspectRatio() method in versions prior to v6.0.0 but note the change of parameter order

See Also