VintaSoft Imaging .NET SDK v8.6
Vintasoft.Imaging.Annotation.UI Namespace / AnnotationViewer Class
Members Example



In This Topic
    AnnotationViewer Class
    In This Topic
    Represents a viewer control for displaying an image collection with annotations.
    Object Model
    AnnotationViewer ClassAnnotationDataCollection ClassAnnotationData ClassAnnotationDataController ClassRectangularSelectionTool ClassAnnotationViewCollection ClassAnnotationView ClassAnnotationViewController ClassAnnotationVisualTool ClassAnnotationData ClassAnnotationView ClassThumbnailAppearance ClassVintasoftImage ClassThumbnailAppearance ClassDecodingSettings ClassRenderingSettings ClassImageCollection ClassVintasoftImage ClassImageViewerBase ClassPaddingF StructureImageRenderingRequirements ClassRotationAssistantArea ClassSelectedAnnotationViewCollection ClassAnnotationView ClassImageViewerState ClassVisualTool Class
    Syntax
    'Declaration
     
    Public Class AnnotationViewer 
       Inherits Vintasoft.Imaging.UI.ImageViewer
    public class AnnotationViewer : Vintasoft.Imaging.UI.ImageViewer 
    public __gc class AnnotationViewer : public Vintasoft.Imaging.UI.ImageViewer 
    public ref class AnnotationViewer : public Vintasoft.Imaging.UI.ImageViewer 
    Remarks
    This control derives from Vintasoft.Imaging.UI.ImageViewer and contains a reference to AnnotationDataController. To access annotations features use the AnnotationDataController or AnnotationViewController properties.

    AnnotationViewer can work in 3 modes:
    • Image mode (AnnotationInteractionMode = None) - annotations are shown, they do not generate events and cannot be modified.
    • View mode (AnnotationInteractionMode = View) - annotations are shown, they generate events but cannot be modified.
    • Author mode (AnnotationInteractionMode = Author) - annotations are shown, they can be selected changed, moved, resized, rotated, deleted, etc using the mouse.

    AnnotationViewer can work separately (viewer will have own image collection) or as a slave viewer of another viewer (viewer will use the image collection of master viewer).
    Example
    This example shows how to add a rectangle annotation to the annotation collection of focused image.
    ' path to an image file
    Private _filePath As String = String.Empty
                
    ''' <summary>
    ''' Clears image collection of image viewer and
    ''' adds image(s) to an image collection of image viewer.
    ''' </summary>
    Private Sub openImageButton_Click(sender As Object, e As System.EventArgs)
        ' select an image file
        If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
            ' clear image collection of the image viewer     
            annotationViewer1.Images.ClearAndDisposeItems()
            ' save a path to an image file
            _filePath = openFileDialog1.FileName
            ' add image file to an image collection of the image viewer
            annotationViewer1.Images.Add(openFileDialog1.FileName, False)
        End If
    End Sub
                
    ''' <summary>
    ''' Saves changes in image collection to the source file.
    ''' </summary>
    Private Sub saveButton_Click(sender As Object, e As System.EventArgs)
        ' create an encoder for image file
        Dim encoder As Vintasoft.Imaging.Codecs.Encoders.EncoderBase = Vintasoft.Imaging.Codecs.Encoders.AvailableEncoders.CreateEncoder(_filePath)
        ' specify that image collection must be switched to the saved image file
        encoder.SaveAndSwitchSource = True
        ' save the image collection to a file
        annotationViewer1.Images.SaveSync(_filePath, encoder)
    End Sub
                
    ''' <summary>
    ''' Saves image collection to a new source.
    ''' </summary>
    Private Sub saveAsImageButton_Click(sender As Object, e As System.EventArgs)
        ' select an image file
        If saveFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
            ' save the image collection to a file
            annotationViewer1.Images.SaveSync(saveFileDialog1.FileName)
        End If
    End Sub
                
    ''' <summary>
    ''' Burns an annotation collection on image.
    ''' </summary>
    Private Sub burnImageButton_Click(sender As Object, e As System.EventArgs)
        annotationViewer1.AnnotationViewController.BurnAnnotationCollectionOnImage(annotationViewer1.Image)
    End Sub
                
    ''' <summary>
    ''' Adds rectangle annotation data to the annotation collection of focused image and 
    ''' starts building of rectangle annotation.
    ''' </summary>
    Private Sub addAndBuildRectangleAnnotationButton_Click(sender As Object, e As System.EventArgs)
        ' change the annotation interaction mode to Author.
        annotationViewer1.AnnotationInteractionMode = Vintasoft.Imaging.Annotation.UI.AnnotationInteractionMode.Author
                
        ' create the rectangle annotation data
        Dim rectData As New Vintasoft.Imaging.Annotation.RectangleAnnotationData()
                
        ' add annotation to the annotation collection of focused image and
        ' start building of annotation
        annotationViewer1.AddAndBuildAnnotation(rectData)
    End Sub
                
    ''' <summary>
    ''' Adds rectangle annotation data to the annotation collection of focused image.
    ''' </summary>
    Private Sub addAndRectangleAnnotationButton_Click(sender As Object, e As System.EventArgs)
        ' change the annotation interaction mode to Author.
        annotationViewer1.AnnotationInteractionMode = Vintasoft.Imaging.Annotation.UI.AnnotationInteractionMode.Author
                
        ' create the rectangle annotation data
        Dim rectData As New Vintasoft.Imaging.Annotation.RectangleAnnotationData()
                
        ' get focused image
        Dim image As Vintasoft.Imaging.VintasoftImage = annotationViewer1.Image
        Dim width As Double = image.Width
        Dim height As Double = image.Height
                
        ' convert pixels to device independent pixels
        width = Vintasoft.Imaging.Utils.UnitOfMeasureConverter.ConvertToDeviceIndependentPixels(width, Vintasoft.Imaging.UnitOfMeasure.Pixels, image.Resolution.Horizontal)
        height = Vintasoft.Imaging.Utils.UnitOfMeasureConverter.ConvertToDeviceIndependentPixels(height, Vintasoft.Imaging.UnitOfMeasure.Pixels, image.Resolution.Vertical)
                
        ' set location of rectangle annotation data
        rectData.Location = New System.Drawing.PointF(CSng(width / 2), CSng(height / 2))
        ' set size of rectangle annotation data
        rectData.Size = New System.Drawing.SizeF(CSng(width * 0.3), CSng(height * 0.3))
                
        ' add annotation to the annotation collection of focused image
        annotationViewer1.AnnotationDataCollection.Add(rectData)
        ' select annotation
        annotationViewer1.FocusedAnnotationData = rectData
    End Sub
    // path to an image file
    private string _filePath = string.Empty;
                
    /// <summary>
    /// Clears image collection of image viewer and
    /// adds image(s) to an image collection of image viewer.
    /// </summary>
    private void openImageButton_Click(object sender, System.EventArgs e)
    {
        // select an image file
        if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            // clear image collection of the image viewer     
            annotationViewer1.Images.ClearAndDisposeItems();
            // save a path to an image file
            _filePath = openFileDialog1.FileName;
            // add image file to an image collection of the image viewer
            annotationViewer1.Images.Add(openFileDialog1.FileName, false);
        }
    }
                
    /// <summary>
    /// Saves changes in image collection to the source file.
    /// </summary>
    private void saveButton_Click(object sender, System.EventArgs e)
    {
        // create an encoder for image file
        Vintasoft.Imaging.Codecs.Encoders.EncoderBase encoder = 
            Vintasoft.Imaging.Codecs.Encoders.AvailableEncoders.CreateEncoder(_filePath);
        // specify that image collection must be switched to the saved image file
        encoder.SaveAndSwitchSource = true;
        // save the image collection to a file
        annotationViewer1.Images.SaveSync(_filePath, encoder);
    }
                
    /// <summary>
    /// Saves image collection to a new source.
    /// </summary>
    private void saveAsImageButton_Click(object sender, System.EventArgs e)
    {
        // select an image file
        if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            // save the image collection to a file
            annotationViewer1.Images.SaveSync(saveFileDialog1.FileName);
        }
    }
                
    /// <summary>
    /// Burns an annotation collection on image.
    /// </summary>
    private void burnImageButton_Click(object sender, System.EventArgs e)
    {
        annotationViewer1.AnnotationViewController.BurnAnnotationCollectionOnImage(annotationViewer1.Image);
    }
                
    /// <summary>
    /// Adds rectangle annotation data to the annotation collection of focused image and 
    /// starts building of rectangle annotation.
    /// </summary>
    private void addAndBuildRectangleAnnotationButton_Click(object sender, System.EventArgs e)
    {
        // change the annotation interaction mode to Author.
        annotationViewer1.AnnotationInteractionMode = Vintasoft.Imaging.Annotation.UI.AnnotationInteractionMode.Author;
                
        // create the rectangle annotation data
        Vintasoft.Imaging.Annotation.RectangleAnnotationData rectData = 
            new Vintasoft.Imaging.Annotation.RectangleAnnotationData();
                
        // add annotation to the annotation collection of focused image and
        // start building of annotation
        annotationViewer1.AddAndBuildAnnotation(rectData);
    }
                
    /// <summary>
    /// Adds rectangle annotation data to the annotation collection of focused image.
    /// </summary>
    private void addAndRectangleAnnotationButton_Click(object sender, System.EventArgs e)
    {
        // change the annotation interaction mode to Author.
        annotationViewer1.AnnotationInteractionMode = Vintasoft.Imaging.Annotation.UI.AnnotationInteractionMode.Author;
                
        // create the rectangle annotation data
        Vintasoft.Imaging.Annotation.RectangleAnnotationData rectData = 
            new Vintasoft.Imaging.Annotation.RectangleAnnotationData();
                
        // get focused image
        Vintasoft.Imaging.VintasoftImage image = annotationViewer1.Image;
        double width = image.Width;
        double height = image.Height;
                
        // convert pixels to device independent pixels
        width = Vintasoft.Imaging.Utils.UnitOfMeasureConverter.ConvertToDeviceIndependentPixels(
            width, Vintasoft.Imaging.UnitOfMeasure.Pixels, image.Resolution.Horizontal);
        height = 
            Vintasoft.Imaging.Utils.UnitOfMeasureConverter.ConvertToDeviceIndependentPixels(
            height, Vintasoft.Imaging.UnitOfMeasure.Pixels, image.Resolution.Vertical);
                
        // set location of rectangle annotation data
        rectData.Location = new System.Drawing.PointF((float)(width / 2), (float)(height / 2));
        // set size of rectangle annotation data
        rectData.Size = new System.Drawing.SizeF((float)(width * 0.3), (float)(height * 0.3));
                
        // add annotation to the annotation collection of focused image
        annotationViewer1.AnnotationDataCollection.Add(rectData);
        // select annotation
        annotationViewer1.FocusedAnnotationData = rectData;
    }
    Inheritance Hierarchy

    System.Object
       System.MarshalByRefObject
          System.ComponentModel.Component
             System.Windows.Forms.Control
                System.Windows.Forms.ScrollableControl
                   Vintasoft.Imaging.UI.ImageViewerBase
                      Vintasoft.Imaging.UI.ImageViewer
                         Vintasoft.Imaging.Annotation.UI.AnnotationViewer

    Requirements

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

    See Also