VintaSoft Imaging .NET SDK 10.0
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:



    Programmatically access to the annotations in WinForms annotation viewer

    The annotation data collection of any image, which is loaded into image viewer, can be accessed using AnnotationViewer.AnnotationDataController property. The annotation data collection of focused image can be get using AnnotationViewer.AnnotationDataCollection property. The data of selected annotation of focused image can be get using AnnotationViewer.FocusedAnnotationData property.

    The collection of annotation visual appearances of any image, which is loaded into image viewer, can be accessed using AnnotationViewer.AnnotationViewController property. The collection of annotation visual appearances of focused image can be get using AnnotationViewer.AnnotationViewCollection property. The visual appearance of selected annotation of focused image can be get using AnnotationViewer.FocusedAnnotationView property.

    The AnnotationViewer raises the AnnotationViewer.AnnotationDataControllerChanged event when image collection is changed. The AnnotationViewer raises the AnnotationViewer.AnnotationViewCollectionChanged event when focused image is changed. The AnnotationViewer raises the AnnotationViewer.FocusedAnnotationViewChanging and AnnotationViewer.FocusedAnnotationViewChanged events when focused annotation is changed.


    Interact with annotations in WinForms annotation viewer

    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 of annotation collection of focused image. This visual tool can be accessed using AnnotationViewer.AnnotationVisualTool property. Detailed information about the AnnotationVisualTool can be found in article Viewing and transforming annotations. Interaction with annotations."

    The second visual tool allows to select multiple annotations on the image using rectangular selection. It can be accessed using AnnotationViewer.AnnotationSelectionTool property.

    By default the AnnotationViewer class creates the composite visual tool, which combines the functionality of both AnnotationViewer.AnnotationVisualTool and AnnotationViewer.AnnotationSelectionTool for more convenient interaction with annotations. Also visual tools can be used separately.

    Here is an example that shows how to create AnnotationViewer, which can scroll image and edit/select annotations of focused image:
    ' The project, which uses this code, must have references to the following assemblies:
    ' - Vintasoft.Imaging
    ' - Vintasoft.Imaging.Annotation.UI
    ' - Vintasoft.Imaging.UI
    
    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
    
    // The project, which uses this code, must have references to the following assemblies:
    // - Vintasoft.Imaging
    // - Vintasoft.Imaging.Annotation.UI
    // - Vintasoft.Imaging.UI
    
    public void SetCompositeVisualTool(
        Vintasoft.Imaging.Annotation.UI.AnnotationViewer annotationViewer)
    {
        annotationViewer.VisualTool = 
            new Vintasoft.Imaging.UI.VisualTools.CompositeVisualTool(
                annotationViewer.AnnotationVisualTool,
                annotationViewer.AnnotationSelectionTool,
                new ScrollPages());
    }
    


    Use different annotation interaction modes in WinForms annotation viewer

    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.

    Detailed information about interaction modes between user and annotations can be foind in article "Viewing and transforming annotations. Interaction with annotations."


    Interact with annotations in WinForms annotation viewer 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:
    ' The project, which uses this code, must have references to the following assemblies:
    ' - Vintasoft.Imaging
    ' - Vintasoft.Imaging.UI
    
    
    ' ...
    
    ''' <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
    
    ' ...
    
    
    // The project, which uses this code, must have references to the following assemblies:
    // - Vintasoft.Imaging
    // - Vintasoft.Imaging.UI
    
    
    // ...
    
    /// <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();
    }
    
    // ...
    
    


    Restrict annotation building/transformation in image region in WinForms annotation viewer

    AnnotationViewer allows to restrict region where annotation can be built or transformed. This functionality can be enabled using AnnotationViewer.IsAnnotationBoundingRectEnabled property. AnnotationViewer.AnnotationBoundingRect property allows to set a region on image, where annotation may be built or transformed.


    Select one or more annotations in WinForms annotation viewer

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

    Detailed information about principles of annotation selection can be found in article "Viewing and transforming annotations. Interaction with annotations."


    Build annotation in WinForms annotation viewer

    The AnnotationViewer.AddAndBuildAnnotation method allows to start the annotation building process, the AnnotationViewer.FinishAnnotationBuilding method allows to finish the annotation building process, the AnnotationViewer.CancelAnnotationBuilding method allows to cancel the annotation building process.
    AnnotationViewer raises the AnnotationViewer.AnnotationBuildingStarted event when annotation building process is started, AnnotationViewer raises the AnnotationViewer.AnnotationBuildingFinished event when annotation building process is finished, AnnotationViewer raises the AnnotationViewer.AnnotationBuildingCanceled event when annotation building process is canceled.

    Detailed information about principles of annotation selection can be found in article "Viewing and transforming annotations. Interaction with annotations."


    Transform annotation in WinForms annotation viewer

    The transformation of focused annotation may be started via mouse.
    AnnotationViewer raises the AnnotationViewer.AnnotationTransformingStarted event when annotation transformation process is started, AnnotationViewer raises the AnnotationViewer.AnnotationTransformingFinished event when annotation transformation process is finished.

    Detailed information about principles of annotation selection can be found in article "Viewing and transforming annotations. Interaction with annotations."


    Expand functionality of WinForms annotation viewer

    AnnotationViewer class has open architecture and allows to change, practically, any functionality in derived classes.