VintaSoft Imaging .NET SDK v8.6
In This Topic
    View images with annotations in WPF
    In This Topic

    WpfAnnotationViewer class, a WPF control - inheritor of WpfImageViewer class, is intended for viewing images with annotations.

    WpfAnnotationViewer class extends the functionality of WpfImageViewer and:



    Access to annotation collection of an image

    The annotation data collection of any image loaded into image viewer can be accessed using WpfAnnotationViewer.AnnotationDataController property. The annotation data collection of active image can be received via WpfAnnotationViewer.AnnotationDataCollection property. The data of selected annotation of active image can be received via WpfAnnotationViewer.FocusedAnnotationData property.

    The collection of annotation visual appearances of any image loaded into image viewer can be accessed using WpfAnnotationViewer.AnnotationViewController property. The collection of annotation visual appearances of active image can be received via WpfAnnotationViewer.AnnotationViewCollection property. The visual appearance of selected annotation of active image can be received via WpfAnnotationViewer.FocusedAnnotationView property.

    The change of image collection in viewer generates WpfAnnotationViewer.AnnotationDataControllerChanged event. The change of current image in viewer generates WpfAnnotationViewer.AnnotationViewCollectionChanged event. The change of current annotation in viewer generates WpfAnnotationViewer.FocusedAnnotationViewChanging and WpfAnnotationViewer.FocusedAnnotationViewChanged event.



    Visual tools which simplify and make more handy working with annotations

    WpfAnnotationViewer class contains 2 visual tools which simplify and make more handy working with annotations.

    The first one is intended for viewing, interaction and editing annotation collection of active image. This visual tool can be accessed via WpfAnnotationViewer.AnnotationVisualTool property. More detailed information about the WpfAnnotationVisualTool see in this article Viewing and transforming annotations. Interaction with annotations."

    The second visual tool allows to select annotation on the image using rectangular selection. It can be accessed via WpfAnnotationViewer.AnnotationSelectionTool property.

    These 2 visual tools can be utilized separately, but for more convenient working with annotations the WpfAnnotationViewer class, by default, creates composite visual tool that integrates the functionality of both WpfAnnotationViewer.AnnotationVisualTool and WpfAnnotationViewer.AnnotationSelectionTool.

    Here is an example showing how the WpfAnnotationViewer class can be provided with abilities to scroll image down, edit and select annotations of active image:
    ' The project, which uses this code, must have references to the following assemblies:
    ' - Vintasoft.Imaging.Annotation.Wpf.UI
    ' - Vintasoft.Imaging.Wpf.UI
    
    Public Sub SetCompositeVisualTool(annotationViewer As Vintasoft.Imaging.Annotation.Wpf.UI.WpfAnnotationViewer)
        annotationViewer.VisualTool = New Vintasoft.Imaging.Wpf.UI.VisualTools.WpfCompositeVisualTool(annotationViewer.AnnotationVisualTool, annotationViewer.AnnotationSelectionTool, New WpfScrollPages())
    End Sub
                  
    
    // The project, which uses this code, must have references to the following assemblies:
    // - Vintasoft.Imaging.Annotation.Wpf.UI
    // - Vintasoft.Imaging.Wpf.UI
    
    public void SetCompositeVisualTool(Vintasoft.Imaging.Annotation.Wpf.UI.WpfAnnotationViewer annotationViewer)
    {
        annotationViewer.VisualTool = 
            new Vintasoft.Imaging.Wpf.UI.VisualTools.WpfCompositeVisualTool(
                annotationViewer.AnnotationVisualTool,
                annotationViewer.AnnotationSelectionTool,
                new WpfScrollPages());
    }
                    
    

    Interaction modes between user and annotations

    WpfAnnotationViewer class allows to choose interaction mode between user and annotations using WpfAnnotationViewer.AnnotationInteractionMode property. The following modes are available:
    WpfAnnotationViewer.AnnotationInteractionModeChanging and WpfAnnotationViewer.AnnotationInteractionModeChanged events are generated when interaction mode between user and annotations is changing and changed in the viewer.

    More detailed information about interaction modes between user and annotations see in this article "Viewing and transforming annotations. Interaction with annotations."



    Interacting with annotations on touch screen

    By default the annotation visual tool has interactive areas, which are comfortable to use if the user works with mouse for interacting with annotation. The default interaction areas are not comfortable to use if the user works with touch screen and interacts with annotation using fingers. Fingers always are thicker than mouse cursor so the interaction areas must be larger for comfortable interaction with annotation on touch screen. The WpfInteractionAreaAppearanceManager class allows to manage settings of interaction areas of visual tool.

    Here is an example that demonstrates how to change the radius and color of points, which allow to scale and rotate annotation:
    ' The project, which uses this code, must have references to the following assemblies:
    ' - Vintasoft.Imaging.Wpf.UI
    
    
    ' ...
    
    ''' <summary>
    ''' Manager of interaction areas.
    ''' </summary>
    Private _interactionAreaAppearanceManager As Vintasoft.Imaging.Wpf.UI.VisualTools.UserInteraction.WpfInteractionAreaAppearanceManager
    
    ' ...
    
    
    ''' <summary>
    ''' Initializes a new instance of the <see cref="MainWindow"/> class.
    ''' </summary>
    Public Sub New()
        ' ...
    
    
            ' ...
        _interactionAreaAppearanceManager = CreateCustomInteractionAreaAppearanceManager(annotationImageViewer1.AnnotationVisualTool)
    End Sub
    
    ' ...
    
    ''' <summary>
    ''' Creates the custom interaction area appearance manager.
    ''' </summary>
    ''' <param name="visualTool">The visual tool.</param>
    ''' <returns>
    ''' The custom interaction area appearance manager.
    ''' </returns>
    Public Function CreateCustomInteractionAreaAppearanceManager(visualTool As Vintasoft.Imaging.Wpf.UI.VisualTools.UserInteraction.WpfUserInteractionVisualTool) As Vintasoft.Imaging.Wpf.UI.VisualTools.UserInteraction.WpfInteractionAreaAppearanceManager
        ' create manager
        Dim manager As New Vintasoft.Imaging.Wpf.UI.VisualTools.UserInteraction.WpfInteractionAreaAppearanceManager()
        manager.VisualTool = visualTool
    
        ' begin the initialization of manager
        manager.BeginInit()
    
        ' resize point
    
        manager.ResizePointsRadius = 10
        manager.ResizePointsInteractionRadius = 10
        manager.ResizePointsBackgroundColor = System.Windows.Media.Color.FromArgb(128, 255, 255, 0)
    
        ' rotation point
    
        manager.RotationPointDistance = 30
        manager.RotationPointRadius = 10
        manager.RotationPointInteractionRadius = 10
        manager.RotationPointBackgroundColor = System.Windows.Media.Color.FromArgb(128, 255, 192, 203)
    
        ' end the initialization of manager
        manager.EndInit()
    
        ' return the manager
        Return manager
    End Function
    
    ' ...
    
    ''' <summary>
    ''' Main form is closed.
    ''' </summary>
    Protected Overrides Sub OnClosed(e As System.EventArgs)
        MyBase.OnClosed(e)
    
        _interactionAreaAppearanceManager.Dispose()
    End Sub
    
    ' ...
    
                  
    
    // The project, which uses this code, must have references to the following assemblies:
    // - Vintasoft.Imaging.Wpf.UI
    
    
    // ...
    
    /// <summary>
    /// Manager of interaction areas.
    /// </summary>
    Vintasoft.Imaging.Wpf.UI.VisualTools.UserInteraction.WpfInteractionAreaAppearanceManager _interactionAreaAppearanceManager;
    
    // ...
    
    
    /// <summary>
    /// Initializes a new instance of the <see cref="MainWindow"/> class.
    /// </summary>
    public MainWindow()
    {
        // ...
    
        _interactionAreaAppearanceManager = CreateCustomInteractionAreaAppearanceManager(annotationImageViewer1.AnnotationVisualTool);
    
        // ...
    }
    
    // ...
    
    /// <summary>
    /// Creates the custom interaction area appearance manager.
    /// </summary>
    /// <param name="visualTool">The visual tool.</param>
    /// <returns>
    /// The custom interaction area appearance manager.
    /// </returns>
    public Vintasoft.Imaging.Wpf.UI.VisualTools.UserInteraction.WpfInteractionAreaAppearanceManager CreateCustomInteractionAreaAppearanceManager(
        Vintasoft.Imaging.Wpf.UI.VisualTools.UserInteraction.WpfUserInteractionVisualTool visualTool)
    {
        // create manager
        Vintasoft.Imaging.Wpf.UI.VisualTools.UserInteraction.WpfInteractionAreaAppearanceManager manager =
            new Vintasoft.Imaging.Wpf.UI.VisualTools.UserInteraction.WpfInteractionAreaAppearanceManager();
        manager.VisualTool = visualTool;
    
        // begin the initialization of manager
        manager.BeginInit();
    
        // resize point
    
        manager.ResizePointsRadius = 10;
        manager.ResizePointsInteractionRadius = 10;
        manager.ResizePointsBackgroundColor = System.Windows.Media.Color.FromArgb(128, 255, 255, 0);
    
        // rotation point
    
        manager.RotationPointDistance = 30;
        manager.RotationPointRadius = 10;
        manager.RotationPointInteractionRadius = 10;
        manager.RotationPointBackgroundColor = System.Windows.Media.Color.FromArgb(128, 255, 192, 203);
    
        // end the initialization of manager
        manager.EndInit();
    
        // return the manager
        return manager;
    }
    
    // ...
    
    /// <summary>
    /// Main form is closed.
    /// </summary>
    protected override void OnClosed(System.EventArgs e)
    {
        base.OnClosed(e);
    
        _interactionAreaAppearanceManager.Dispose();
    }
    
    // ...
    
                    
    



    Image region where annotation may be built or transformed

    WpfAnnotationViewer.IsAnnotationBoundingRectEnabled property allows to define if the region, where annotation may be built or transformed, is subject to a restriction. WpfAnnotationViewer.AnnotationBoundingRect property allows to set a region on the image, where annotation may be built or transformed.



    Selection of one or more annotations

    By default, WpfAnnotationViewer class allows to select several annotations. The selected annotation collection can be received using WpfAnnotationViewer.SelectedAnnotations property. The ability of multiple annotations selection can be disabled using WpfAnnotationViewer.AnnotationMultiSelect property.

    More detailed information about principles of annotation selection see in this article "Viewing and transforming annotations. Interaction with annotations."



    Building of annotations

    To start the process of visual annotation building should be called WpfAnnotationViewer.AddAndBuildAnnotation method, to force the finish - WpfAnnotationViewer.FinishAnnotationBuilding method, and to cancel the process - WpfAnnotationViewer.CancelAnnotationBuilding method.
    Before building of annotation starts is generated WpfAnnotationViewer.AnnotationBuildingStarted event, when finished - WpfAnnotationViewer.AnnotationBuildingFinished event, and when canceled - WpfAnnotationViewer.AnnotationBuildingCanceled event.

    More detailed information about principles of annotation selection see in this article "Viewing and transforming annotations. Interaction with annotations."



    Transformation of annotation

    The process of selected annotation visual transformation may be started via mouse.
    Before transformation of annotation starts is generated WpfAnnotationViewer.AnnotationTransformingStarted event, when finished - WpfAnnotationViewer.AnnotationTransformingFinished event.

    More detailed information about principles of annotation selection see in this article "Viewing and transforming annotations. Interaction with annotations."



    Expanding of existing functionality

    WpfAnnotationViewer class is open for deriving and allows to change, practically, any functionality in derived classes.