VintaSoft Imaging .NET SDK 14.0: Документация для .NET разработчика
В этом разделе
    Связь между изображением и коллекцией данных аннотаций
    В этом разделе
    Класс AnnotationDataController хранит связи между изображениями в ImageCollection и коллекциями данных аннотаций (AnnotationDataCollection).
    Класс AnnotationDataController позволяет:

    Вот C#/VB.NET код, который демонстрирует, как загрузить коллекцию изображений, добавить аннотацию к первому изображению и сохранить результаты в новый файл:
    Vintasoft.Imaging.ImageCollection imageCollection = new Vintasoft.Imaging.ImageCollection();
    imageCollection.Add(@"d:\Images\AutoContrast.jpg");
    imageCollection.Add(@"d:\Images\AutoColors.jpg");
    imageCollection.Add(@"d:\Images\AutoLevels.jpg");
    imageCollection.Add(@"d:\Images\Background.jpg");
    
    Vintasoft.Imaging.Annotation.AnnotationDataController annotationDataController = 
        new Vintasoft.Imaging.Annotation.AnnotationDataController(imageCollection);
    
    Vintasoft.Imaging.Annotation.RectangleAnnotationData rectangleAnnotationData = 
        new Vintasoft.Imaging.Annotation.RectangleAnnotationData();
    rectangleAnnotationData.Location = new System.Drawing.PointF(340, 150);
    rectangleAnnotationData.Size = new System.Drawing.SizeF(220, 150);
    
    annotationDataController[0].Add(rectangleAnnotationData);
    
    imageCollection.SaveSync(@"d:\ImageCollection.tif", true);
    
    Dim imageCollection As New Vintasoft.Imaging.ImageCollection()
    imageCollection.Add("d:\Images\AutoContrast.jpg")
    imageCollection.Add("d:\Images\AutoColors.jpg")
    imageCollection.Add("d:\Images\AutoLevels.jpg")
    imageCollection.Add("d:\Images\Background.jpg")
    
    Dim annotationDataController As New Vintasoft.Imaging.Annotation.AnnotationDataController(imageCollection)
    
    Dim rectangleAnnotationData As New Vintasoft.Imaging.Annotation.RectangleAnnotationData()
    rectangleAnnotationData.Location = New System.Drawing.PointF(340, 150)
    rectangleAnnotationData.Size = New System.Drawing.SizeF(220, 150)
    
    annotationDataController(0).Add(rectangleAnnotationData)
    
    imageCollection.SaveSync("d:\ImageCollection.tif", True)
    


    AnnotationDataController генерирует следующие события:
    Вот C#/VB.NET код, который демонстрирует, как фильтровать аннотации при загрузке коллекции аннотаций:
    /// <summary>
    /// Adds filtering of annotations when annotation collection is loaded.
    /// </summary>
    public static void AddAnnotationsLoadFilter(Vintasoft.Imaging.Annotation.UI.AnnotationViewer viewer)
    {
        // Subscribe to the AnnotationsDataChanged event of viewer.
        SubscribeToViewerEvents(viewer);
    
        // Subscribe to the CollectionAdded event of annotation data controller.
        SubscribeToControllerEvents(viewer.AnnotationDataController);
    }
    
    /// <summary>
    /// Subscribe to the AnnotationsDataChanged event of viewer.
    /// </summary>
    private static void SubscribeToViewerEvents(Vintasoft.Imaging.Annotation.UI.AnnotationViewer viewer)
    {
        viewer.AnnotationDataControllerChanged += 
            new System.EventHandler<Vintasoft.Imaging.Annotation.AnnotationDataControllerChangedEventArgs>(viewer_AnnotationsDataChanged);
    }
    
    /// <summary>
    /// Handler of the AnnotationsDataChanged event.
    /// </summary>
    private static void viewer_AnnotationsDataChanged(object sender, 
        Vintasoft.Imaging.PropertyChangedEventArgs<Vintasoft.Imaging.Annotation.AnnotationDataController> e)
    {
        // Unsubscribe from the events of previous annotation data controller.
        UnsubscribeFromControllerEvents(e.OldValue);
    
        // Subscribe to the events of new annotation data controller.
        SubscribeToControllerEvents(e.NewValue);
    }
    
    /// <summary>
    /// Subscribe to the CollectionAdded event of annotation data controller.
    /// </summary>
    private static void SubscribeToControllerEvents(Vintasoft.Imaging.Annotation.AnnotationDataController dataController)
    {
        dataController.CollectionAdded += 
            new System.EventHandler<Vintasoft.Imaging.Annotation.AnnotationDataControllerDataCollectionEventArgs>(dataController_CollectionAdded);
    }
    
    /// <summary>
    /// Unsubscribe from the CollectionAdded event of annotation data controller.
    /// </summary>
    private static void UnsubscribeFromControllerEvents(Vintasoft.Imaging.Annotation.AnnotationDataController dataController)
    {
        if (dataController != null)
            dataController.CollectionAdded -= 
                new System.EventHandler<Vintasoft.Imaging.Annotation.AnnotationDataControllerDataCollectionEventArgs>(dataController_CollectionAdded);
    }
    
    /// <summary>
    /// Handler of the CollectionAdded event.
    /// </summary>
    private static void dataController_CollectionAdded(object sender, 
        Vintasoft.Imaging.Annotation.AnnotationDataControllerDataCollectionEventArgs e)
    {
        // Annotation data collection is added to the annotation data controller,
        // at this moment we can filter annotations.
    
        // Filter the annotations.
        ApplyAnnotationFilter(e.AnnotationDataCollection);
    }
    
    /// <summary>
    /// Filters the annotations of annotation data collection.
    /// </summary>
    private static void ApplyAnnotationFilter(Vintasoft.Imaging.Annotation.AnnotationDataCollection dataCollection)
    {
        // For each annotation in collection.
        foreach (Vintasoft.Imaging.Annotation.AnnotationData data in dataCollection)
        {
            // If annotation is stamp.
            if (data is Vintasoft.Imaging.Annotation.StampAnnotationData)
                // Make annotation invisible.
                data.IsVisible = false;
        }
    }
    
    ''' <summary>
    ''' Adds filtering of annotations when annotation collection is loaded.
    ''' </summary>
    Public Shared Sub AddAnnotationsLoadFilter(viewer As Vintasoft.Imaging.Annotation.UI.AnnotationViewer)
        ' Subscribe to the AnnotationsDataChanged event of viewer.
        SubscribeToViewerEvents(viewer)
    
        ' Subscribe to the CollectionAdded event of annotation data controller.
        SubscribeToControllerEvents(viewer.AnnotationDataController)
    End Sub
    
    ''' <summary>
    ''' Subscribe to the AnnotationsDataChanged event of viewer.
    ''' </summary>
    Private Shared Sub SubscribeToViewerEvents(viewer As Vintasoft.Imaging.Annotation.UI.AnnotationViewer)
        AddHandler viewer.AnnotationDataControllerChanged, New System.EventHandler(Of Vintasoft.Imaging.Annotation.AnnotationDataControllerChangedEventArgs)(AddressOf viewer_AnnotationsDataChanged)
    End Sub
    
    ''' <summary>
    ''' Handler of the AnnotationsDataChanged event.
    ''' </summary>
    Private Shared Sub viewer_AnnotationsDataChanged(sender As Object, e As Vintasoft.Imaging.PropertyChangedEventArgs(Of Vintasoft.Imaging.Annotation.AnnotationDataController))
        ' Unsubscribe from the events of previous annotation data controller.
        UnsubscribeFromControllerEvents(e.OldValue)
    
        ' Subscribe to the events of new annotation data controller.
        SubscribeToControllerEvents(e.NewValue)
    End Sub
    
    ''' <summary>
    ''' Subscribe to the CollectionAdded event of annotation data controller.
    ''' </summary>
    Private Shared Sub SubscribeToControllerEvents(dataController As Vintasoft.Imaging.Annotation.AnnotationDataController)
        AddHandler dataController.CollectionAdded, New System.EventHandler(Of Vintasoft.Imaging.Annotation.AnnotationDataControllerDataCollectionEventArgs)(AddressOf dataController_CollectionAdded)
    End Sub
    
    ''' <summary>
    ''' Unsubscribe from the CollectionAdded event of annotation data controller.
    ''' </summary>
    Private Shared Sub UnsubscribeFromControllerEvents(dataController As Vintasoft.Imaging.Annotation.AnnotationDataController)
        If dataController IsNot Nothing Then
            RemoveHandler dataController.CollectionAdded, New System.EventHandler(Of Vintasoft.Imaging.Annotation.AnnotationDataControllerDataCollectionEventArgs)(AddressOf dataController_CollectionAdded)
        End If
    End Sub
    
    ''' <summary>
    ''' Handler of the CollectionAdded event.
    ''' </summary>
    Private Shared Sub dataController_CollectionAdded(sender As Object, e As Vintasoft.Imaging.Annotation.AnnotationDataControllerDataCollectionEventArgs)
        ' Annotation data collection is added to the annotation data controller,
        ' at this moment we can filter annotations.
    
        ' Filter the annotations.
        ApplyAnnotationFilter(e.AnnotationDataCollection)
    End Sub
    
    ''' <summary>
    ''' Filters the annotations of annotation data collection.
    ''' </summary>
    Private Shared Sub ApplyAnnotationFilter(dataCollection As Vintasoft.Imaging.Annotation.AnnotationDataCollection)
        ' For each annotation in collection.
        For Each data As Vintasoft.Imaging.Annotation.AnnotationData In dataCollection
            ' If annotation is stamp.
            If TypeOf data Is Vintasoft.Imaging.Annotation.StampAnnotationData Then
                ' Make annotation invisible.
                data.IsVisible = False
            End If
        Next
    End Sub