ImageEn, unit imageenview




function GetIdealZoom(Cropping: Double = 0): Double; overload;
function GetIdealZoom(CanStretch, CanShrink: Boolean; FitMode: TIEFitMode): double; overload;
procedure GetIdealZoom(out x, y: double; IgnoreScrollBars: Boolean = False); overload;


Returns the best zoom value to stretch the image to fit within the component. If second overload is used, independent Zoom values are given for x and y (Optionally you can calculate value without the effect of the scrollbars).
Cropping specifies the amount of image that can be hidden (top/left of portrait images, or left/right side of landscape images) to better fill the control. This value is a percentage of the difference between the min and max zooms, so 0.0 means no cropping, whereas 1.0 would completely fill the control (see examples below).

Note: If the image is empty, result will be zero.


// Both the following code snippets will have the same result
ImageEnView.Zoom := ImageEnView.GetIdealZoom;

// or

// Zoom to fit width
ImageEnView.GetIdealZoom( ZoomX, ZoomY );
ImageEnView.Zoom := ZoomX;

// Zoom to fill control by cropping image view (while maintaining the aspect ratio)
ImageEnView.GetIdealZoom( ZoomX, ZoomY );
ImageEnView.Zoom := dmax( ZoomX, ZoomY );

// Stretch image to control size without maintaining the aspect ratio
ImageEnView.GetIdealZoom( ZoomX, ZoomY );
ImageEnView.ZoomX := ZoomX;
ImageEnView.ZoomY := ZoomY;

Cropping Examples

// 0% cropping (resulting in 17.9% zoom)
ImageEnView.Zoom := ImageEnView.GetIdealZoom( 0.0 );

// 33% cropping (resulting in 19.4% zoom)
ImageEnView.Zoom := ImageEnView.GetIdealZoom( 0.33 );

// 66% cropping (resulting in 21.8% zoom)
ImageEnView.Zoom := ImageEnView.GetIdealZoom( 0.66 );

// Full cropping (resulting in 24.3% zoom)
ImageEnView.Zoom := ImageEnView.GetIdealZoom( 1.0 );

// Full cropping without scrollbars (resulting in 25.9% zoom)
ImageEnView1.ScrollBars := ssNone;
ImageEnView.Zoom := ImageEnView.GetIdealZoom( 1.0 );

// 200% cropping (resulting in 31.6% zoom)
ImageEnView.Zoom := ImageEnView.GetIdealZoom( 2.0 );

See Also

- loFitToLayersWhenZooming
- IdealComponentWidth
- IdealComponentHeight
- IdealImageWidth
- IdealImageHeight