VintaSoft Imaging .NET SDK 12.4: Documentation for .NET developer
Vintasoft.Imaging.Annotation.Wpf.UI.Measurements Namespace / WpfImageMeasureTool Class
Members Object Syntax Example Hierarchy Requirements SeeAlso
In This Topic
    WpfImageMeasureTool Class
    In This Topic
    Visual tool that allows to measure objects on images in image viewer.
    Object Model
    WpfMeasurementAnnotationView AnnotationFont AnnotationFont WpfAnnotationView WpfAnnotationView WpfAnnotationViewCollection WpfRotationAssistantArea WpfRotationPoint CopyItemUIAction CutItemUIAction PasteItemWithOffsetUIAction DeleteItemUIAction SelectAllItemsUIAction DeselectAllItemsUIAction DeleteAllItemsUIAction IObjectClipboard SelectedWpfAnnotationViewCollection IWpfInteractionController WpfImageViewer WpfImageMeasureTool
    Syntax
    'Declaration
    
    <DesignTimeVisibleAttribute("Visible = False")>
    <ToolboxItemAttribute("ToolboxItemType = null", "ToolboxItemTypeName = ")>
    <DefaultPropertyAttribute("Content")>
    <ContentPropertyAttribute("Content")>
    <LocalizabilityAttribute(None)>
    <StyleTypedPropertyAttribute("Property = FocusVisualStyle", "StyleTargetType = System.Windows.Controls.Control")>
    <XmlLangPropertyAttribute("Name = Language")>
    <UsableDuringInitializationAttribute("Usable = True")>
    <RuntimeNamePropertyAttribute("Name = Name")>
    <UidPropertyAttribute()>
    <TypeDescriptionProviderAttribute("TypeName = MS.Internal.ComponentModel.DependencyObjectProvider")>
    <NameScopePropertyAttribute("Name = NameScope", "Type = System.Windows.NameScope")>
    Public Class WpfImageMeasureTool
       Inherits Vintasoft.Imaging.Annotation.Wpf.UI.VisualTools.WpfAnnotationVisualTool
    
    
    [DesignTimeVisible("Visible = False")]
    [ToolboxItem("ToolboxItemType = null", "ToolboxItemTypeName = ")]
    [DefaultProperty("Content")]
    [ContentProperty("Content")]
    [Localizability(None)]
    [StyleTypedProperty("Property = FocusVisualStyle", "StyleTargetType = System.Windows.Controls.Control")]
    [XmlLangProperty("Name = Language")]
    [UsableDuringInitialization("Usable = True")]
    [RuntimeNameProperty("Name = Name")]
    [UidProperty()]
    [TypeDescriptionProvider("TypeName = MS.Internal.ComponentModel.DependencyObjectProvider")]
    [NameScopeProperty("Name = NameScope", "Type = System.Windows.NameScope")]
    public class WpfImageMeasureTool : Vintasoft.Imaging.Annotation.Wpf.UI.VisualTools.WpfAnnotationVisualTool
    
    
    [DesignTimeVisible("Visible = False")]
    [ToolboxItem("ToolboxItemType = null", "ToolboxItemTypeName = ")]
    [DefaultProperty("Content")]
    [ContentProperty("Content")]
    [Localizability(None)]
    [StyleTypedProperty("Property = FocusVisualStyle", "StyleTargetType = System.Windows.Controls.Control")]
    [XmlLangProperty("Name = Language")]
    [UsableDuringInitialization("Usable = True")]
    [RuntimeNameProperty("Name = Name")]
    [UidProperty()]
    [TypeDescriptionProvider("TypeName = MS.Internal.ComponentModel.DependencyObjectProvider")]
    [NameScopeProperty("Name = NameScope", "Type = System.Windows.NameScope")]
    public __gc class WpfImageMeasureTool : public Vintasoft.Imaging.Annotation.Wpf.UI.VisualTools.WpfAnnotationVisualTool*
    
    
    [DesignTimeVisible("Visible = False")]
    [ToolboxItem("ToolboxItemType = null", "ToolboxItemTypeName = ")]
    [DefaultProperty("Content")]
    [ContentProperty("Content")]
    [Localizability(None)]
    [StyleTypedProperty("Property = FocusVisualStyle", "StyleTargetType = System.Windows.Controls.Control")]
    [XmlLangProperty("Name = Language")]
    [UsableDuringInitialization("Usable = True")]
    [RuntimeNameProperty("Name = Name")]
    [UidProperty()]
    [TypeDescriptionProvider("TypeName = MS.Internal.ComponentModel.DependencyObjectProvider")]
    [NameScopeProperty("Name = NameScope", "Type = System.Windows.NameScope")]
    public ref class WpfImageMeasureTool : public Vintasoft.Imaging.Annotation.Wpf.UI.VisualTools.WpfAnnotationVisualTool^
    
    
    Example

    This C#/VB.NET code 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 = Vintasoft.Imaging.AnchorType.Center
    
        ' 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 = Vintasoft.Imaging.AnchorType.Center;
    
        // 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: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    See Also