ImageEn, unit imageenview |
|
TImageEnView.GetIdealZoom
Declaration
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;
Description
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
ImageEnView.Fit();
// 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 );
ImageEnView1.CenterImage();
// 33% cropping (resulting in 19.4% zoom)
ImageEnView.Zoom := ImageEnView.GetIdealZoom( 0.33 );
ImageEnView1.CenterImage();
// 66% cropping (resulting in 21.8% zoom)
ImageEnView.Zoom := ImageEnView.GetIdealZoom( 0.66 );
ImageEnView1.CenterImage();
// Full cropping (resulting in 24.3% zoom)
ImageEnView.Zoom := ImageEnView.GetIdealZoom( 1.0 );
ImageEnView1.CenterImage();
// Full cropping without scrollbars (resulting in 25.9% zoom)
ImageEnView1.ScrollBars := ssNone;
ImageEnView.Zoom := ImageEnView.GetIdealZoom( 1.0 );
ImageEnView1.CenterImage();
// 200% cropping (resulting in 31.6% zoom)
ImageEnView.Zoom := ImageEnView.GetIdealZoom( 2.0 );
ImageEnView1.CenterImage();
See Also
◼loFitToLayersWhenZooming
◼IdealComponentWidth
◼IdealComponentHeight
◼IdealImageWidth
◼IdealImageHeight