VintaSoft Imaging .NET SDK v8.7
Vintasoft.Imaging.Annotation.Wpf.UI.Measurements Namespace / WpfImageMeasureTool Class
Members Example



In This Topic
    WpfImageMeasureTool Class
    In This Topic
    Visual tool that allows to measure objects on images in image viewer.
    Object Model
    WpfImageMeasureTool ClassIWpfInteractionController InterfaceWpfAnnotationViewCollection ClassWpfAnnotationView ClassIObjectClipboard InterfaceCopyItemUIAction ClassCutItemUIAction ClassDeleteItemUIAction ClassDeleteAllItemsUIAction ClassDeselectAllItemsUIAction ClassWpfAnnotationView ClassIWpfInteractiveObject InterfaceWpfMeasurementAnnotationView ClassAnnotationFont ClassWpfAnnotationView ClassWpfImageViewer ClassPasteItemWithOffsetUIAction ClassWpfRotationAssistantArea ClassWpfRotationPoint ClassSelectAllItemsUIAction ClassSelectedWpfAnnotationViewCollection ClassWpfAnnotationView ClassAnnotationFont Class
    Syntax
    Example
    This example shows how to measure the diagonal size, in pixels, of image in image viewer.
    ''' <summary>
    ''' Returns the diagonal size of image in image viewer in pixels.
    ''' </summary>
    ''' <param name="viewer">An image viewer.</param>
    ''' <returns>The diagonal size of image in image viewer in pixels.</returns>
    ''' <remarks>
    ''' Creates a measurement annotation to measure the diagonal.
    ''' </remarks>
    Public Shared Function GetDiagonalImageSizeExample(viewer As Vintasoft.Imaging.Wpf.UI.WpfImageViewer) As Double
        ' create the image measure tool
        Dim imageMeasureTool As New Vintasoft.Imaging.Annotation.Wpf.UI.Measurements.WpfImageMeasureTool()
                
        ' set visual tool as the active visual tool of image viewer
        viewer.VisualTool = imageMeasureTool
                
        ' create an annotation, which will display the measurement line
        Dim measurementLine As New Vintasoft.Imaging.Annotation.Measurements.LinearMeasuringData()
        ' set the start point of measurement line
        measurementLine.Points.Add(New System.Drawing.PointF(0, 0))
        ' set the end point of measurement line
        measurementLine.Points.Add(New System.Drawing.PointF(viewer.Image.Width, viewer.Image.Height))
        ' set pixels as units of measure for measurement line
        measurementLine.UnitsOfMeasure = Vintasoft.Imaging.UnitOfMeasure.Pixels
                
        ' create an annotation, which will display the measurement result
        Dim measurementResult As New Vintasoft.Imaging.Annotation.Measurements.MeasurementAnnotationData(measurementLine)
        ' set the text template for annotation with measurement result
        measurementResult.MeasuringTextTemplate = "{Length:f2} pixels"
        ' set the text block alignment for annotation with measurement result
        measurementResult.TextBlockAlignment = System.Drawing.ContentAlignment.MiddleCenter
                
        ' create the view for annotation with measurement result
        Dim measurementResultView As New Vintasoft.Imaging.Annotation.Wpf.UI.Measurements.WpfMeasurementAnnotationView(measurementResult)
                
        ' add annotation with measurement result to the annotation collection of image measure tool
        imageMeasureTool.AnnotationViewCollection.Add(measurementResultView)
                
        ' get measured value
        Dim measuredValues As System.Collections.Generic.Dictionary(Of String, Double) = measurementLine.GetMeasuredValues(viewer.Image)
                
        ' return length of the diagonal line
        Return measuredValues("Length")
    End Function
    /// <summary>
    /// Returns the diagonal size of image in image viewer in pixels.
    /// </summary>
    /// <param name="viewer">An image viewer.</param>
    /// <returns>The diagonal size of image in image viewer in pixels.</returns>
    /// <remarks>
    /// Creates a measurement annotation to measure the diagonal.
    /// </remarks>
    public static double GetDiagonalImageSizeExample(Vintasoft.Imaging.Wpf.UI.WpfImageViewer viewer)
    {
        // create the image measure tool
        Vintasoft.Imaging.Annotation.Wpf.UI.Measurements.WpfImageMeasureTool imageMeasureTool =
            new Vintasoft.Imaging.Annotation.Wpf.UI.Measurements.WpfImageMeasureTool();
                
        // set visual tool as the active visual tool of image viewer
        viewer.VisualTool = imageMeasureTool;
                
        // create an annotation, which will display the measurement line
        Vintasoft.Imaging.Annotation.Measurements.LinearMeasuringData measurementLine =
            new Vintasoft.Imaging.Annotation.Measurements.LinearMeasuringData();
        // set the start point of measurement line
        measurementLine.Points.Add(new System.Drawing.PointF(0, 0));
        // set the end point of measurement line
        measurementLine.Points.Add(new System.Drawing.PointF(viewer.Image.Width, viewer.Image.Height));
        // set pixels as units of measure for measurement line
        measurementLine.UnitsOfMeasure = Vintasoft.Imaging.UnitOfMeasure.Pixels;
                
        // create an annotation, which will display the measurement result
        Vintasoft.Imaging.Annotation.Measurements.MeasurementAnnotationData measurementResult =
            new Vintasoft.Imaging.Annotation.Measurements.MeasurementAnnotationData(measurementLine);
        // set the text template for annotation with measurement result
        measurementResult.MeasuringTextTemplate = "{Length:f2} pixels";
        // set the text block alignment for annotation with measurement result
        measurementResult.TextBlockAlignment = System.Drawing.ContentAlignment.MiddleCenter;
                
        // create the view for annotation with measurement result
        Vintasoft.Imaging.Annotation.Wpf.UI.Measurements.WpfMeasurementAnnotationView measurementResultView =
            new Vintasoft.Imaging.Annotation.Wpf.UI.Measurements.WpfMeasurementAnnotationView(measurementResult);
                
        // add annotation with measurement result to the annotation collection of image measure tool
        imageMeasureTool.AnnotationViewCollection.Add(measurementResultView);
                
        // get measured value
        System.Collections.Generic.Dictionary<string, double> measuredValues = measurementLine.GetMeasuredValues(viewer.Image);
                
        // return length of the diagonal line
        return measuredValues["Length"];
    }
    Inheritance Hierarchy

    System.Object
       System.Windows.Threading.DispatcherObject
          System.Windows.DependencyObject
             System.Windows.Media.Visual
                System.Windows.UIElement
                   System.Windows.FrameworkElement
                      System.Windows.Controls.Control
                         System.Windows.Controls.ContentControl
                            Vintasoft.Imaging.Wpf.UI.VisualTools.WpfVisualTool
                               Vintasoft.Imaging.Wpf.UI.VisualTools.UserInteraction.WpfUserInteractionVisualTool
                                  Vintasoft.Imaging.Annotation.Wpf.UI.VisualTools.WpfAnnotationVisualTool
                                     Vintasoft.Imaging.Annotation.Wpf.UI.Measurements.WpfImageMeasureTool

    Requirements

    Target Platforms: Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

    See Also