(Leadtools.Controls)

Zoom Method

Show in webframe
Example 





The zoom mode to use.
The desired scale factor.
The origin of the zoom operation.
Zooms or changes the size mode of the image inside the viewer.
Syntax
public virtual void Zoom( 
   ImageViewerSizeMode sizeMode,
   double scaleFactor,
   Point origin
)
Public Overridable Sub Zoom( _
   ByVal sizeMode As ImageViewerSizeMode, _
   ByVal scaleFactor As Double, _
   ByVal origin As Point _
) 
public virtual void Zoom( 
   ImageViewerSizeMode sizeMode,
   double scaleFactor,
   Point origin
)
-(void)zoomWithSizeMode:(LTImageViewerSizeMode) sizeMode
            scaleFactor:(double)aScaleFactor
                 origin:(CGPoint)anOrigin;
            
public void zoom(ImageViewerSizeMode sizeMode,
                 float scaleFactor, 
                 PointF origin)
            
 function Leadtools.Controls.ImageViewer.Zoom( 
   sizeMode ,
   scaleFactor ,
   origin 
)

Parameters

sizeMode
The zoom mode to use.
scaleFactor
The desired scale factor.
origin
The origin of the zoom operation.
Remarks

The following factors affect the current zoom value of the image inside the viewer:

A combination of the above will result in an actual x and y zoom value (they will be different if the size mode is ImageViewerSizeMode.Stretch for example). These values can be obtained by reading the value of the read-only CurrentXScaleFactor and CurrentYScaleFactor. If the stretch size mode is not used in your application, the CurrentScaleFactor helper property will return the maximum of the x and y scale factors (which are equal in all cases but stretch).

For example, to fit the image in the current viewer size, you use the following: SizeMode = ImageViewerSizeMode.Fit and ScaleFactor = 1.


            viewer.SizeMode = Leadtools.Controls.ImageViewerSizeMode.fit;
            viewer.ScaleFactor = 1;
            
The viewer may have to zoom the image out to make it fit if the image size is greater than the control size. In this situation the actual zoom value is not 1, but a value less than 1. As a result, the ScaleFactor will be 1 (since you are not doing any scaling) but CurrentScaleFactor will be less than 1 (since the viewer has to zoom the image out).

Anytime you change the value of ScaleFactor or SizeMode, the control will re-calculate the transformation matrix required to draw the image. This matrix can be obtained at any time by querying the Transform read only property.

Since changing SizeMode and ScaleFactor will cause the viewer to recalculate the transformation and request a render operation for each change, it is recommended that you disable the update and re-enable it to combine both operations and enhance performance:


            viewer.BeginUpdate(); //Prevents the viewer from automatically updating
            
            viewer.SizeMode = Leadtools.Controls.ImageViewerSizeMode.Fit;
            viewer.ScaleFactor = 1;
            
            viewer.EndUpdate(); //Completes the update, allowing the viewer to re-render
            

Generally, you might use the ImageViewer control to display images in two ways:

  1. An application that sets the size mode to a value and leaves it, such as ImageViewerSizeMode.None, ImageViewerSizeMode.Fit or ImageViewerSizeMode.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.

  2. 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, change the values of SizeMode and ScaleFactor directly like the example above. Typically, the values are set and are not changed later.

For the second type of applications, it is recommended that you do not use the SizeMode and ScaleFactor properties directly to set the required zooming and image fit. Instead, use the helper Zoom method that accepts all the necessary information needed to perform common zoom and size mode operations. The previous code snippet can be changed into this single line:


            viewer.Zoom(Leadtools.Controls.ImageViewerSizeMode.Fit, 1, viewer.DefaultZoomOrigin);
            

As well as taking care of the update issue, the Zoom method also allows you to specify the zoom operation origin. In the example above, the image will zoom in around the default point for current alignment (ImageHorizontalAlignment and ImageVerticalAlignment).

Example
Copy Code  
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Controls;

void ZoomExample(ImageViewerSizeMode sizeMode, bool resetZoom, bool zoomIn, bool zoomOut)
{
   if (resetZoom)//if resetZoom Changed reset Zoom to %100
   {
      _viewer.Zoom(sizeMode, 1, _viewer.DefaultZoomOrigin);
   }
   else if (zoomIn)//if zoomIn zoom to %120
   {
      var zoomFactor = 1.2;
      _viewer.Zoom(sizeMode, _viewer.CurrentScaleFactor * zoomFactor, _viewer.DefaultZoomOrigin);
   }
   else if (zoomOut)//if zoomout zoom to %83.33
   {
      var zoomFactor = 1.2;
      _viewer.Zoom(sizeMode, _viewer.CurrentScaleFactor / zoomFactor, _viewer.DefaultZoomOrigin);
   }
}
Requirements

Target Platforms

See Also

Reference

ImageViewer Class
ImageViewer Members

 

 


Products | Support | Contact Us | Copyright Notices
© 2006-2014 All Rights Reserved. LEAD Technologies, Inc.