ImageEn, unit imageenview




procedure Fit(StretchSmall : Boolean = True; Cropping: Double = 0.0);


Adjusts Zoom so that the image fits within the client area of the component (while respecting the aspect ratio).
If StretchSmall is false, then images that are smaller than the window are shown 1:1 (i.e. are not zoomed more than 100%).
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: Fit will only have a temporary effect if AutoShrink or AutoStretch is enabled, unless you add iedoDisableAutoFitWhenZoom to DisplayOptions

Example 1

// Display the entire image (including outlying layers) within the view
ImageEnView1.LayerOptions := ImageEnView1.LayerOptions + [ loFitToLayersWhenZooming ];
ImageEnView1.Fit( False );

Example 2

// Zoom so layers fill entire view area

// Make IEView consider all layers when calculating image bounds
ImageEnView1.LayerOptions := ImageEnView1.LayerOptions + [loDynamicCanvas];

// Position layers so origin is 0,0
rect := ImageEnView1.LayersRect(False, True);
ImageEnView1.LayersRepositionAll(-rect.X, - rect.Y);

// Adjust zoom so all layers fill the view area

Cropping Examples

// 0% cropping (resulting in 17.9% zoom)
ImageEnView1.Fit( True, 0.0 );

// 33% cropping (resulting in 19.4% zoom)
ImageEnView1.Fit( True, 0.33 );

// 66% cropping (resulting in 21.8% zoom)
ImageEnView1.Fit( True, 0.66 );

// Full cropping (resulting in 24.3% zoom)
ImageEnView1.Fit( True, 1.0 );

// Full cropping without scrollbars (resulting in 25.9% zoom)
ImageEnView1.ScrollBars := ssNone;
ImageEnView1.Fit( True, 1.0 );

// 200% cropping (resulting in 31.6% zoom)
ImageEnView1.Fit( True, 2.0 );

See Also