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

    AnnotationViewer class, a WinForms control - inheritor of ImageViewer class, is intended for viewing images with annotations.

    AnnotationViewer class extends the functionality of ImageViewer and:



    Access to annotation collection of an image

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

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

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



    Visual tools which simplify and make more handy working with annotations

    AnnotationViewer 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 AnnotationViewer.AnnotationVisualTool property. More detailed information about the AnnotationVisualTool 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 AnnotationViewer.AnnotationSelectionTool property.

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

    Here is an example showing how the AnnotationViewer class can be provided with abilities to scroll image down, edit and select annotations of active image:
    Public Sub SetCompositeVisualTool(annotationViewer As Vintasoft.Imaging.Annotation.UI.AnnotationViewer)
        annotationViewer.VisualTool = New Vintasoft.Imaging.UI.VisualTools.CompositeVisualTool(annotationViewer.AnnotationVisualTool, annotationViewer.AnnotationSelectionTool, New ScrollPages())
    End Sub
                  
    
    public void SetCompositeVisualTool(
        Vintasoft.Imaging.Annotation.UI.AnnotationViewer annotationViewer)
    {
        annotationViewer.VisualTool = 
            new Vintasoft.Imaging.UI.VisualTools.CompositeVisualTool(
                annotationViewer.AnnotationVisualTool,
                annotationViewer.AnnotationSelectionTool,
                new ScrollPages());
    }
                    
    

    Interaction modes between user and annotations

    AnnotationViewer class allows to choose interaction mode between user and annotations using AnnotationViewer.AnnotationInteractionMode property. The following modes are available:
    AnnotationViewer.AnnotationInteractionModeChanging and AnnotationViewer.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 InteractionAreaAppearanceManager 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:
    ' ...
    
    ''' <summary>
    ''' Manager of interaction areas.
    ''' </summary>
    Private _interactionAreaAppearanceManager As Vintasoft.Imaging.UI.VisualTools.UserInteraction.InteractionAreaAppearanceManager
    
    ' ...
    
    
    ''' <summary>
    ''' Initializes a new instance of the <see cref="MainForm"/> 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.UI.VisualTools.UserInteraction.UserInteractionVisualTool) As Vintasoft.Imaging.UI.VisualTools.UserInteraction.InteractionAreaAppearanceManager
        ' create manager
        Dim manager As New Vintasoft.Imaging.UI.VisualTools.UserInteraction.InteractionAreaAppearanceManager()
        manager.VisualTool = visualTool
    
        ' begin the initialization of manager
        manager.BeginInit()
    
        ' resize point
    
        manager.ResizePointsRadius = 10
        manager.ResizePointsInteractionRadius = 10
        manager.ResizePointsBackgroundColor = System.Drawing.Color.FromArgb(128, System.Drawing.Color.Yellow)
    
        ' rotation point
    
        manager.RotationPointDistance = 30
        manager.RotationPointRadius = 10
        manager.RotationPointInteractionRadius = 10
        manager.RotationPointBackgroundColor = System.Drawing.Color.FromArgb(128, System.Drawing.Color.Pink)
    
        ' end the initialization of manager
        manager.EndInit()
    
        ' return the manager
        Return manager
    End Function
    
    ' ...
    
    ''' <summary>
    ''' Main form is closed.
    ''' </summary>
    Protected Overrides Sub OnFormClosed(e As System.Windows.Forms.FormClosedEventArgs)
        MyBase.OnFormClosed(e)
    
        _interactionAreaAppearanceManager.Dispose()
    End Sub
    
    ' ...
    
                  
    
    // ...
    
    /// <summary>
    /// Manager of interaction areas.
    /// </summary>
    Vintasoft.Imaging.UI.VisualTools.UserInteraction.InteractionAreaAppearanceManager _interactionAreaAppearanceManager;
    
    // ...
    
    
    /// <summary>
    /// Initializes a new instance of the <see cref="MainForm"/> class.
    /// </summary>
    public MainForm()
    {
        // ...
    
        _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.UI.VisualTools.UserInteraction.InteractionAreaAppearanceManager CreateCustomInteractionAreaAppearanceManager(
    Vintasoft.Imaging.UI.VisualTools.UserInteraction.UserInteractionVisualTool visualTool)
    {
        // create manager
        Vintasoft.Imaging.UI.VisualTools.UserInteraction.InteractionAreaAppearanceManager manager =
            new Vintasoft.Imaging.UI.VisualTools.UserInteraction.InteractionAreaAppearanceManager();
        manager.VisualTool = visualTool;
    
        // begin the initialization of manager
        manager.BeginInit();
    
        // resize point
    
        manager.ResizePointsRadius = 10;
        manager.ResizePointsInteractionRadius = 10;
        manager.ResizePointsBackgroundColor = System.Drawing.Color.FromArgb(128, System.Drawing.Color.Yellow);
    
        // rotation point
    
        manager.RotationPointDistance = 30;
        manager.RotationPointRadius = 10;
        manager.RotationPointInteractionRadius = 10;
        manager.RotationPointBackgroundColor = System.Drawing.Color.FromArgb(128, System.Drawing.Color.Pink);
    
        // end the initialization of manager
        manager.EndInit();
    
        // return the manager
        return manager;
    }
    
    // ...
    
    /// <summary>
    /// Main form is closed.
    /// </summary>
    protected override void OnFormClosed(System.Windows.Forms.FormClosedEventArgs e)
    {
        base.OnFormClosed(e);
    
        _interactionAreaAppearanceManager.Dispose();
    }
    
    // ...
    
                    
    



    Image region where annotation may be built or transformed

    AnnotationViewer.IsAnnotationBoundingRectEnabled property allows to define if the region, where annotation may be built or transformed, is subject to a restriction. AnnotationViewer.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, AnnotationViewer class allows to select several annotations. The selected annotation collection can be received using AnnotationViewer.SelectedAnnotations property. The ability of multiple annotations selection can be disabled using AnnotationViewer.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 AnnotationViewer.AddAndBuildAnnotation method, to force the finish - AnnotationViewer.FinishAnnotationBuilding method, and to cancel the process - AnnotationViewer.CancelAnnotationBuilding method.
    Before building of annotation starts is generated AnnotationViewer.AnnotationBuildingStarted event, when finished - AnnotationViewer.AnnotationBuildingFinished event, and when canceled - AnnotationViewer.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 AnnotationViewer.AnnotationTransformingStarted event, when finished - AnnotationViewer.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

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