Zooms or changes the size mode of the view.
Public Overridable Sub Zoom(
ByVal sizeMode As ControlSizeMode,
ByVal zoomValue As Double,
ByVal origin As LeadPoint
The size mode to use.
The desired zoom value. This must be a value greater than 0. A value of 1.0 equals 100 percent zoom, a value of 0.5 equals to 50 percent, a value of 1.5 equals 150 percent zoom and so on.
The origin of the zoom operation.
|ImageViewerSingleViewLayout||The view size is the size of the current ActiveItem, a fit page operation will fit the active item inside the viewer, a fit width operation will fit the width of the active item inside the viewer and so on.|
|ImageViewerVerticalViewLayout||The view size is dependant on the value of Columns, for example, if the column count is 0, then the view layout will try to fit as much items in the viewer horizontally as possible before moving to the next row. If the column count is any other number, then the view will fill the columns with that exact number of items before moving to the next row. The width of the view is maximum total width of the items in any column, the height of the view is the total height of all the rows.|
|ImageViewerHorizontalViewLayout||The view size is dependant on the value of Rows, for example, if the row count is 0, then the view layout will try to fit as much items in the viewer vertically as possible before moving to the next row. If the column count is any other number, then the view will fill the rows with that exact number of items before moving to the next column. The height of the view is maximum total height of the items in any row, the width of the view is the total width of all the columns.|
The following factors affect the current zoom value of the view:
The size mode (SizeMode), (whether it is none, fit, fit width, fit height or stretch).
The current scale factor (ScaleFactor). A value of 1 means no scaling 100 percent), a value of 0.5 means 50 percent, 1.5 means 150 percent, 2 means 200 percent and so forth
The aspect ratio correction (AspectRatioCorrection). Use this value to manually stretch the view vertically.
A combination of the above will result in an actual x and y zoom value (they will be different if the size mode is ControlSizeMode.Stretch for example). These values can always be obtained by reading the value of the read-only XScaleFactor and YScaleFactor. If stretch size mode is not used in your application, then Use ScaleFactor which is a helper property that returns the maximum of x, y scale factors (which are equal in all cases but stretch).
For example, to fit the view in the current viewer area, use the following: sizeMode = ControlSizeMode.Fit and zoomValue = 1. The viewer might zoom the view out to make it fit if the size is greater than the control size. Hence, the actual scale factor (will be stored in ScaleFactor after the method returns ) is not 1, but a value less than 1. Since the viewer has to zoom the total image out.
To zoom the viewer in and out, obtain the current scale factor and multiply it by the increment or decrement value. For example, to zoom the viewer in by 200% (makes it twice as big), use:
// Multiply the current scale factor by two
viewer.Zoom(ControlSizeMode.None, viewer.ScaleFactor * 2.0, viewer.DefaultZoomOrigin);
The following zooms the viewer out by 50% (makes it half as big)
// Multiply the current scale factor by half
viewer.Zoom(ControlSizeMode.None, viewer.ScaleFactor * 0.5, viewer.DefaultZoomOrigin);
To zoom the viewer in by 50% (makes it one and half times bigger), use:
// Multiply the current scale factor by one and a half
viewer.Zoom(ControlSizeMode.None, viewer.ScaleFactor * 1.5, viewer.DefaultZoomOrigin);
And to zoom the viewer out by 25% (make it quarter of the size)
// Multiply the current scale factor by quarter
viewer.Zoom(ControlSizeMode.None, viewer.ScaleFactor * 0.25, viewer.DefaultZoomOrigin);
You can also use a different size mode. For example, to fit the whole view into the current viewer use:
viewer.Zoom(ControlSizeMode.Fit, 1.0, viewer.DefaultZoomOrigin);
As you can see, we passed 1.0 (or 100%) as the scale factor because the viewer will calculate the actual scaling values needed to perform "Fit". Similarly the following will fit the view width to take the whole viewer horizontal space while maintaining the aspect ratio:
viewer.Zoom(ControlSizeMode.FitWidth, 1.0, viewer.DefaultZoomOrigin);
All the ControlSizeMode's support fitting to the desired size and then applying a zoom, so:
viewer.Zoom(ControlSizeMode.Fit, 2.0, viewer.DefaultZoomOrigin);
Will fit the view into the available viewer space and then zooms it by 2.
All the size modes listed above maintain the aspect ratio of the view. And hence, the values of XScaleFactor and YScaleFactor will be the same. However, when you want to fit the view into the control area extending to fill each direction, you use:
viewer.Zoom(ControlSizeMode.Stretch, 1.0, viewer.DefaultZoomOrigin);
zoomValue must be a value between MinimumScaleFactor and MaximumScaleFactor. The default values can be changed to support smaller or larger legal scale factor values. However, since Zoom is called by other parts of the framework (for example, the ImageViewerPanZoomInteractiveMode), a default cut-off value is needed so the viewer does not zoom outside user-controlled values. Passing a zoomValue value outside the minimum and maximum range will have no affect and will be ignored.
Anytime you change ScaleFactor or SizeMode by calling Zoom, the control will re-calculate the transformation matrices and view layout required to place and render the view and items as requested on the viewer by internally calling UpdateTransform. The view transformation matrix will be stored in ViewTransform while the matrices for the items and their images can be updated using GetItemTransform or GetItemImageTransform.
Generally, you might use the ImageViewer control to display images in two ways:
An application that sets the size mode to a value and leave it, such as ControlSizeMode.None, ControlSizeMode.Fit or ControlSizeMode.Stretch. An example of this would be an application that displays thumbnails or a static image. In other words, the application will not have zoom in/out functionality for the viewer.
An application that requires zooming as well as optionally changing the size mode. An example of this would be a document viewer application.
For the first types of applications, call Zoom once with the desired size mode and a zoom value of 1.0. The size mode is stored by the viewer and will be applied whenever the viewer control size changes. For the second type of applications, call Zoom as many times as desired with the necessary information. These application typically has a zoom in/out button as well as optionally a way to set the size mode. As well as taking care of the update issue, the Zoom method also allows you to specify the zoom operation origin. The DefaultZoomOrigin can be used for most cases. This is defined by the values of ViewHorizontalAlignment and ViewVerticalAlignment. For example, when ViewHorizontalAlignment is ControlAlignment.Near, the X value of the zoom origin is the left edge of the view. With ControlAlignment.Center it is at the center of the view width. Finally with ControlAlignment.Near it is at the right edge of the view. The zoom origin works similarly with ViewVerticalAlignment and using the view top, middle and bottom edges. The ImageViewerPanZoomInteractiveMode and ImageViewerZoomAtInteractiveMode modes use this method to perform their actions. For more information refer to Image Viewer Appearance, Image Viewer Transformation, Image Viewer Bounds and Transform, Image Viewer Layouts and Image Viewer Rendering.
This example will implement a zoom operation similar to popular document viewers such as Adobe Acrobat Reader.