Класс ImageViewerImagesManager
Асинхронно управляет изображениями просмотрщика изображений.
Вот C#/VB.NET код, который демонстрирует, как использовать менеджер изображений, который асинхронно добавляет изображения в просмотрщик изображений (менеджер извлекает информацию о изображениях из файла в течение 1 секунды, добавляет изображения в просмотрщик изображений, выполняет предыдущие шаги до тех пор, пока информация о всех изображениях не будет извлечена).
''' <summary>
''' The images manager for an image viewer.
''' </summary>
Private _imagesManager As Vintasoft.Imaging.UI.ImageViewerImagesManager
''' <summary>
''' Initializes a new instance of the <see cref="MainForm1"/> class.
''' </summary>
Public Sub New()
InitializeComponent()
' create images manager
_imagesManager = New Vintasoft.Imaging.UI.ImageViewerImagesManager(imageViewer1)
' specify that manager should retrieve information about image from file during 1 second, add images to an image viewer,
' do previous steps until information about all images will not be retrieved
_imagesManager.IntermediateAddInterval = 1000
' specify that manager should work asynchronously
_imagesManager.IsAsync = True
AddHandler _imagesManager.ImageSourceAddException, AddressOf ImagesManager_ImageSourceAddException
End Sub
''' <summary>
''' Opens an image file.
''' </summary>
''' <param name="filename">The filename.</param>
Friend Sub OpenImageFile(filename As String)
' cancel previous file opening process
CancelOpening()
' clear image collection of manager
_imagesManager.Images.ClearAndDisposeItems()
' add image file to the manager
_imagesManager.Add(filename)
End Sub
''' <summary>
''' Cancels the opening of a file.
''' </summary>
Private Sub CancelOpening()
_imagesManager.Cancel()
End Sub
Private Sub ImagesManager_ImageSourceAddException(sender As Object, e As Vintasoft.Imaging.ImageSourceExceptionEventArgs)
Dim message As String = String.Format("Cannot open {0} : {1}", System.IO.Path.GetFileName(e.SourceFilename), e.Exception.Message)
System.Windows.Forms.MessageBox.Show(message, "Error")
End Sub
/// <summary>
/// The images manager for an image viewer.
/// </summary>
Vintasoft.Imaging.UI.ImageViewerImagesManager _imagesManager;
/// <summary>
/// Initializes a new instance of the <see cref="MainForm1"/> class.
/// </summary>
public MainForm1()
{
InitializeComponent();
// create images manager
_imagesManager = new Vintasoft.Imaging.UI.ImageViewerImagesManager(imageViewer1);
// specify that manager should retrieve information about image from file during 1 second, add images to an image viewer,
// do previous steps until information about all images will not be retrieved
_imagesManager.IntermediateAddInterval = 1000;
// specify that manager should work asynchronously
_imagesManager.IsAsync = true;
_imagesManager.ImageSourceAddException += ImagesManager_ImageSourceAddException;
}
/// <summary>
/// Opens an image file.
/// </summary>
/// <param name="filename">The filename.</param>
internal void OpenImageFile(string filename)
{
// cancel previous file opening process
CancelOpening();
// clear image collection of manager
_imagesManager.Images.ClearAndDisposeItems();
// add image file to the manager
_imagesManager.Add(filename);
}
/// <summary>
/// Cancels the opening of a file.
/// </summary>
private void CancelOpening()
{
_imagesManager.Cancel();
}
private void ImagesManager_ImageSourceAddException(object sender, Vintasoft.Imaging.ImageSourceExceptionEventArgs e)
{
string message = string.Format("Cannot open {0} : {1}", System.IO.Path.GetFileName(e.SourceFilename), e.Exception.Message);
System.Windows.Forms.MessageBox.Show(message, "Error");
}
System.Object
 Vintasoft.Imaging.ImageCollectionManager
   Vintasoft.Imaging.UI.ImageViewerImagesManager
Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5