(Leadtools.Controls)

ScaleFactor Property (ImageViewer)

Show in webframe
Example 





Gets or sets the scale factor used to display the image.
Syntax
public double ScaleFactor {get; set;}
Public Property ScaleFactor As Double
public double ScaleFactor {get; set;}
@property (nonatomic) double scaleFactor;
public float getScaleFactor()
public void setScaleFactor(float scaleFactor)
            
 
get_ScaleFactor();
set_ScaleFactor(value);
Object.defineProperty('ScaleFactor');

Property Value

The scale factor used to display the image. A value of 1.0 means 100 percent, a value of 1.5 means 150 percent, a value of 2.0 = 200 percent and so on. The default value is 1.0.
Remarks

Changing the value of this property will fire the PropertyChanged and TransformChanged events.

The following 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 (these values will be different if the size mode is ImageViewerSizeMode.Stretch for example). These values can be obtained by reading the values of the read-only CurrentXScaleFactor and CurrentYScaleFactor. If stretch size mode is not used in your application, then the CurrentScaleFactor helper property will return the maximum of x, y scale factors (which are equal in all cases except when the size mode is set to stretch).

For example, to fit the image in the current viewer size, set the SizeMode equal to ImageViewerSizeMode.Fit and set the ScaleFactor equal to 1.


            viewer.SizeMode = Leadtools.Controls.ImageViewerSizeMode.fit;
            viewer.ScaleFactor = 1;
            
The viewer may 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).

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. Set the size mode to a value and leave it, such as ImageViewerSizeMode.None, ImageViewerSizeMode.Fit or ImageViewerSizeMode.Stretch. For example, to display thumbnails or a static image. This application will not have zoom in/out functionality for the viewer.

  2. The application requires zooming as well as changing the size mode. An example of this is a document viewer application.

For the first type of application, you can change the value of SizeMode and ScaleFactor directly like the example above. Since you generally set it to a value and do not change it.

For the second type of application, 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. Zoom 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, Zoom also allows you to specify the origin for the zoom operation. 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;

[TestMethod]
public void ScaleFactorExample()
{
   bool zoomIn = false;
   // Set the new values in _viewer
   double scaleFactor = _viewer.ScaleFactor;

   if (zoomIn)
   {
      // Zoom in
      scaleFactor *= 2;

      if (scaleFactor > 8)
      {
         // Zoom out next time
         zoomIn = false;
      }
   }
   else
   {
      // Zoom out
      scaleFactor /= 2;
      if (scaleFactor < 0.0125)
      {
         // Zoom in next time
         zoomIn = true;
      }
   }

   _viewer.ScaleFactor = scaleFactor;

   // Show the values in the label
   _infoLabel.Text = "Scale factor = " + _viewer.ScaleFactor;
}
Requirements

Target Platforms

See Also

Reference

ImageViewer Class
ImageViewer Members

 

 


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