VintaSoft Twain .NET SDK 15.1: Руководство для .NET разработчика
Vintasoft.WpfTwain Namespace / ExtendedImageInfoCollection Class
Члены типа Объект Синтаксис Example Иерархия Требования Смотрите также
В этом разделе
    Класс ExtendedImageInfoCollection
    В этом разделе
    Класс, позволяющий извлекать расширенную информацию о отсканированном изображении.
    Объектная модель
    ExtendedImageInfo ExtendedImageInfoCollection
    Синтаксис
    'Declaration
    
    <DefaultMemberAttribute("Item")>
    Public NotInheritable Class ExtendedImageInfoCollection
       Inherits System.Collections.CollectionBase
    
    
    [DefaultMember("Item")]
    public sealed class ExtendedImageInfoCollection : System.Collections.CollectionBase
    
    
    [DefaultMember("Item")]
    public __gc __sealed class ExtendedImageInfoCollection : public System.Collections.CollectionBase*
    
    
    [DefaultMember("Item")]
    public ref class ExtendedImageInfoCollection sealed : public System.Collections.CollectionBase^
    
    
    Пример

    Вот C#/VB.NET код, который демонстрирует, как получить расширенную информацию (номер документа, номер страницы, камеру, номер кадра, кадр, тип пикселя) о полученном изображении.

    
    Partial Public Class How_to_get_extended_information_about_acquired_image
        Inherits Form
    
        ''' <summary>
        ''' TWAIN device manager.
        ''' </summary>
        Private _deviceManager As Vintasoft.Twain.DeviceManager
    
    
    
        Public Sub New()
            InitializeComponent()
    
            ' create and open device manager
            _deviceManager = New Vintasoft.Twain.DeviceManager(Me, Me.Handle)
            _deviceManager.Open()
        End Sub
    
    
    
        ''' <summary>
        ''' Acquire images asynchronously.
        ''' </summary>
        Public Sub AcquireImagesAsynchronously()
            Try
                ' get reference to the default device
                Dim device1 As Vintasoft.Twain.Device = _deviceManager.DefaultDevice
    
                ' subscribe to the device events
                AddHandler device1.ImageAcquired, New EventHandler(Of Vintasoft.Twain.ImageAcquiredEventArgs)(AddressOf device_ImageAcquired)
                AddHandler device1.ScanFinished, New EventHandler(AddressOf device_ScanFinished)
    
                ' set scanning settings
                device1.TransferMode = Vintasoft.Twain.TransferMode.Memory
                device1.ShowUI = False
                device1.DisableAfterAcquire = True
    
                ' open the device
                device1.Open()
    
                ' specify that extended information about acquired image is necessary
                device1.ExtendedImageInfo.Add(New Vintasoft.Twain.ExtendedImageInfo(Vintasoft.Twain.ExtendedImageInfoId.DocumentNumber))
                device1.ExtendedImageInfo.Add(New Vintasoft.Twain.ExtendedImageInfo(Vintasoft.Twain.ExtendedImageInfoId.PageNumber))
                device1.ExtendedImageInfo.Add(New Vintasoft.Twain.ExtendedImageInfo(Vintasoft.Twain.ExtendedImageInfoId.Camera))
                device1.ExtendedImageInfo.Add(New Vintasoft.Twain.ExtendedImageInfo(Vintasoft.Twain.ExtendedImageInfoId.FrameNumber))
                device1.ExtendedImageInfo.Add(New Vintasoft.Twain.ExtendedImageInfo(Vintasoft.Twain.ExtendedImageInfoId.Frame))
                device1.ExtendedImageInfo.Add(New Vintasoft.Twain.ExtendedImageInfo(Vintasoft.Twain.ExtendedImageInfoId.PixelFlavor))
    
                ' acquire images asynchronously
                device1.Acquire()
            Catch ex As Vintasoft.Twain.TwainException
                MessageBox.Show(ex.Message)
            End Try
        End Sub
    
        ''' <summary>
        ''' Image is acquired.
        ''' </summary>
        Private Sub device_ImageAcquired(ByVal sender As Object, ByVal e As Vintasoft.Twain.ImageAcquiredEventArgs)
            ' output an extended information about the acquired image
    
            extendedImageInfoAboutAcquiredImageTextBox.Text += "IMAGE IS ACQUIRED" + Environment.NewLine
            extendedImageInfoAboutAcquiredImageTextBox.Text += Environment.NewLine
    
            Dim device As Vintasoft.Twain.Device = DirectCast(sender, Vintasoft.Twain.Device)
            For i As Integer = 0 To device.ExtendedImageInfo.Count - 1
                AddExtendedImageInfoToResultTextBox(i, device.ExtendedImageInfo(i))
            Next
            extendedImageInfoAboutAcquiredImageTextBox.Text += Environment.NewLine
    
            ' dispose the acquired image
            e.Image.Dispose()
        End Sub
    
        ''' <summary>
        ''' Add an extended image info to the result text box.
        ''' </summary>
        Private Sub AddExtendedImageInfoToResultTextBox(ByVal index As Integer, ByVal info As Vintasoft.Twain.ExtendedImageInfo)
            If Not info.IsValueValid Then
                Return
            End If
    
            extendedImageInfoAboutAcquiredImageTextBox.Text += String.Format("Extended image info {0}", index)
            extendedImageInfoAboutAcquiredImageTextBox.Text += Environment.NewLine
    
            extendedImageInfoAboutAcquiredImageTextBox.Text += String.Format("  Name={0}", [Enum].GetName(GetType(Vintasoft.Twain.ExtendedImageInfoId), info.InfoId))
            extendedImageInfoAboutAcquiredImageTextBox.Text += Environment.NewLine
    
            extendedImageInfoAboutAcquiredImageTextBox.Text += String.Format("  Id={0}", info.InfoId)
            extendedImageInfoAboutAcquiredImageTextBox.Text += Environment.NewLine
    
            extendedImageInfoAboutAcquiredImageTextBox.Text += String.Format("  Value type={0}", info.ValueType)
            extendedImageInfoAboutAcquiredImageTextBox.Text += Environment.NewLine
    
            Dim oneDeviceCapabilityValue As Vintasoft.Twain.TwainOneValueContainer = TryCast(info.Value, Vintasoft.Twain.TwainOneValueContainer)
            If oneDeviceCapabilityValue IsNot Nothing Then
                extendedImageInfoAboutAcquiredImageTextBox.Text += String.Format("  Value={0}", oneDeviceCapabilityValue.Value)
                extendedImageInfoAboutAcquiredImageTextBox.Text += Environment.NewLine
            Else
                Dim arrayDeviceCapabilityValue As Vintasoft.Twain.TwainArrayValueContainer = TryCast(info.Value, Vintasoft.Twain.TwainArrayValueContainer)
                If arrayDeviceCapabilityValue IsNot Nothing Then
                    extendedImageInfoAboutAcquiredImageTextBox.Text += "Values: "
                    If arrayDeviceCapabilityValue.Values.[GetType]() Is GetType(Byte()) Then
                        extendedImageInfoAboutAcquiredImageTextBox.Text += String.Format("byte[{0}]", arrayDeviceCapabilityValue.Values.Length)
                    Else
                        For i As Integer = 0 To arrayDeviceCapabilityValue.Values.Length - 1
                            extendedImageInfoAboutAcquiredImageTextBox.Text += String.Format("{0}, ", arrayDeviceCapabilityValue.Values.GetValue(i))
                        Next
                    End If
                    extendedImageInfoAboutAcquiredImageTextBox.Text += Environment.NewLine
                End If
            End If
        End Sub
    
        ''' <summary>
        ''' Scan is finished.
        ''' </summary>
        Private Sub device_ScanFinished(ByVal sender As Object, ByVal e As EventArgs)
            Dim device1 As Vintasoft.Twain.Device = DirectCast(sender, Vintasoft.Twain.Device)
    
            ' unsubscribe from device events
            RemoveHandler device1.ImageAcquired, New EventHandler(Of Vintasoft.Twain.ImageAcquiredEventArgs)(AddressOf device_ImageAcquired)
            RemoveHandler device1.ScanFinished, New EventHandler(AddressOf device_ScanFinished)
    
            ' if device is not closed
            If device1.State <> Vintasoft.Twain.DeviceState.Closed Then
                ' close the device
                device1.Close()
            End If
    
            MessageBox.Show("Scan is finished.")
        End Sub
    
    End Class
    
    
    
    namespace TwainExamples_CSharp
    {
        public partial class How_to_get_extended_information_about_acquired_image : System.Windows.Forms.Form
        {
    
            /// <summary>
            /// TWAIN device manager.
            /// </summary>
            Vintasoft.Twain.DeviceManager _deviceManager;
    
    
    
            public How_to_get_extended_information_about_acquired_image()
            {
                InitializeComponent();
    
                // create and open device manager
                _deviceManager = new Vintasoft.Twain.DeviceManager(this, this.Handle);
                _deviceManager.Open();
            }
    
    
    
            /// <summary>
            /// Acquire images asynchronously.
            /// </summary>
            public void AcquireImagesAsynchronously()
            {
                try
                {
                    // get reference to the default device
                    Vintasoft.Twain.Device device = _deviceManager.DefaultDevice;
    
                    // subscribe to the device events
                    device.ImageAcquired += new System.EventHandler<Vintasoft.Twain.ImageAcquiredEventArgs>(device_ImageAcquired);
                    device.ScanFinished += new System.EventHandler(device_ScanFinished);
    
                    // set scanning settings
                    device.TransferMode = Vintasoft.Twain.TransferMode.Memory;
                    device.ShowUI = false;
                    device.DisableAfterAcquire = true;
    
                    // open the device
                    device.Open();
    
                    // specify that extended information about acquired image is necessary
                    device.ExtendedImageInfo.Add(new Vintasoft.Twain.ExtendedImageInfo(Vintasoft.Twain.ExtendedImageInfoId.DocumentNumber));
                    device.ExtendedImageInfo.Add(new Vintasoft.Twain.ExtendedImageInfo(Vintasoft.Twain.ExtendedImageInfoId.PageNumber));
                    device.ExtendedImageInfo.Add(new Vintasoft.Twain.ExtendedImageInfo(Vintasoft.Twain.ExtendedImageInfoId.Camera));
                    device.ExtendedImageInfo.Add(new Vintasoft.Twain.ExtendedImageInfo(Vintasoft.Twain.ExtendedImageInfoId.FrameNumber));
                    device.ExtendedImageInfo.Add(new Vintasoft.Twain.ExtendedImageInfo(Vintasoft.Twain.ExtendedImageInfoId.Frame));
                    device.ExtendedImageInfo.Add(new Vintasoft.Twain.ExtendedImageInfo(Vintasoft.Twain.ExtendedImageInfoId.PixelFlavor));
    
                    // acquire images asynchronously
                    device.Acquire();
                }
                catch (Vintasoft.Twain.TwainException ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
            }
    
            /// <summary>
            /// Image is acquired.
            /// </summary>
            private void device_ImageAcquired(object sender, Vintasoft.Twain.ImageAcquiredEventArgs e)
            {
                // output an extended information about the acquired image
    
                extendedImageInfoAboutAcquiredImageTextBox.Text += "IMAGE IS ACQUIRED" + System.Environment.NewLine;
                extendedImageInfoAboutAcquiredImageTextBox.Text += System.Environment.NewLine;
    
                Vintasoft.Twain.Device device = (Vintasoft.Twain.Device)sender;
                for (int i = 0; i < device.ExtendedImageInfo.Count; i++)
                {
                    AddExtendedImageInfoToResultTextBox(i, device.ExtendedImageInfo[i]);
                }
                extendedImageInfoAboutAcquiredImageTextBox.Text += System.Environment.NewLine;
    
                // dispose the acquired image
                e.Image.Dispose();            
            }
    
            /// <summary>
            /// Add an extended image info to the result text box.
            /// </summary>
            private void AddExtendedImageInfoToResultTextBox(int index, Vintasoft.Twain.ExtendedImageInfo info)
            {
                if (!info.IsValueValid)
                    return;
    
                extendedImageInfoAboutAcquiredImageTextBox.Text += string.Format("Extended image info {0}", index);
                extendedImageInfoAboutAcquiredImageTextBox.Text += System.Environment.NewLine;
    
                extendedImageInfoAboutAcquiredImageTextBox.Text += string.Format("  Name={0}", System.Enum.GetName(typeof(Vintasoft.Twain.ExtendedImageInfoId), info.InfoId));
                extendedImageInfoAboutAcquiredImageTextBox.Text += System.Environment.NewLine;
    
                extendedImageInfoAboutAcquiredImageTextBox.Text += string.Format("  Id={0}", info.InfoId);
                extendedImageInfoAboutAcquiredImageTextBox.Text += System.Environment.NewLine;
    
                extendedImageInfoAboutAcquiredImageTextBox.Text += string.Format("  Value type={0}", info.ValueType);
                extendedImageInfoAboutAcquiredImageTextBox.Text += System.Environment.NewLine;
    
                Vintasoft.Twain.TwainOneValueContainer oneDeviceCapabilityValue = info.Value as Vintasoft.Twain.TwainOneValueContainer;
                if (oneDeviceCapabilityValue != null)
                {
                    extendedImageInfoAboutAcquiredImageTextBox.Text += string.Format("  Value={0}", oneDeviceCapabilityValue.Value);
                    extendedImageInfoAboutAcquiredImageTextBox.Text += System.Environment.NewLine;
                }
                else
                {
                    Vintasoft.Twain.TwainArrayValueContainer arrayDeviceCapabilityValue = info.Value as Vintasoft.Twain.TwainArrayValueContainer;
                    if (arrayDeviceCapabilityValue != null)
                    {
                        extendedImageInfoAboutAcquiredImageTextBox.Text += "Values: ";
                        if (arrayDeviceCapabilityValue.Values.GetType() == typeof(byte[]))
                        {
                            extendedImageInfoAboutAcquiredImageTextBox.Text += string.Format("byte[{0}]", arrayDeviceCapabilityValue.Values.Length);
                        }
                        else
                        {
                            for (int i = 0; i < arrayDeviceCapabilityValue.Values.Length; i++)
                                extendedImageInfoAboutAcquiredImageTextBox.Text += string.Format("{0}, ", arrayDeviceCapabilityValue.Values.GetValue(i));
                        }
                        extendedImageInfoAboutAcquiredImageTextBox.Text += System.Environment.NewLine;
                    }
                }
            }
            
            /// <summary>
            /// Scan is finished.
            /// </summary>
            void device_ScanFinished(object sender, System.EventArgs e)
            {
                Vintasoft.Twain.Device device = (Vintasoft.Twain.Device)sender;
    
                // unsubscribe from device events
                device.ImageAcquired -= new System.EventHandler<Vintasoft.Twain.ImageAcquiredEventArgs>(device_ImageAcquired);
                device.ScanFinished -= new System.EventHandler(device_ScanFinished);
    
                // if device is not closed
                if (device.State != Vintasoft.Twain.DeviceState.Closed)
                    // close the device
                    device.Close();
    
                System.Windows.Forms.MessageBox.Show("Scan is finished.");
            }
    
        }
    }
    
    

    Иерархия наследования

    System.Object
       System.Collections.CollectionBase
          Vintasoft.WpfTwain.ExtendedImageInfoCollection

    Требования

    Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5

    Смотрите также