VintaSoft Twain .NET SDK 14.1: Руководство для .NET разработчика
В этом разделе
    Как использовать функцию Dual Stream сканера Kodak?
    В этом разделе
    SDK позволяет использовать функцию Dual Stream сканеров Kodak.


    Функция Dual Stream означает, что сканер имеет несколько "камер" и может делать несколько снимков каждой сканируемой страницы. Каждая камера имеет предопределенные настройки (тип пикселя и часть страницы) и настраиваемые параметры (разрешение, яркость, контрастность, порог, фильтры и т.д.).

    Например, большинство сканеров Kodak имеют 6 камер:

    Вот C#/VB.NET код, который демонстрирует, как получить обе части страницы в виде черно-белого и цветного изображений с разным разрешением:
    /// <summary>
    /// Synchronously acquire images from Kodak scanner and uses Kodak dual stream feature.
    /// </summary>
    public void SynchronouslyAcquireImagesFromKodakScannerAndUseDualStreamFeature()
    {
        try
        {
            using (Vintasoft.Twain.DeviceManager deviceManager = new Vintasoft.Twain.DeviceManager())
            {
                // open the device manager
                deviceManager.Open();
    
                // get reference to the default device
                Vintasoft.Twain.Device device = deviceManager.DefaultDevice;
    
                // set scanning settings
                device.TransferMode = Vintasoft.Twain.TransferMode.Memory;
                device.ShowUI = false;
    
                // open the device
                device.Open();
    
                // set inches as units of measure
                device.UnitOfMeasure = Vintasoft.Twain.UnitOfMeasure.Inches;
                // enable duplex
                device.DocumentFeeder.DuplexEnabled = true;
    
                // select color camera
                device.Cameras.SetSelectedCamera("/Camera_Color_Both");
                // set resolution for color images
                device.Resolution = new Vintasoft.Twain.Resolution(300, 300);
                // enable color camera
                device.Cameras.EnableSelectedCamera();
    
                // select black-white camera
                device.Cameras.SetSelectedCamera("/Camera_Bitonal_Both");
                // set resolution for black-white images
                device.Resolution = new Vintasoft.Twain.Resolution(200, 200);
                // enable black-white camera
                device.Cameras.EnableSelectedCamera();
    
                // synchronously acquire image(s) from TWAIN device
                Vintasoft.Twain.AcquireModalState acquireModalState;
                do
                {
                    acquireModalState = device.AcquireModal();
                    switch (acquireModalState)
                    {
                        case Vintasoft.Twain.AcquireModalState.ImageAcquired:
                            // get info about acquired image
                            Vintasoft.Twain.ImageInfo acquiredImageInfo = device.AcquiredImage.ImageInfo;
                            // show message box with info about acquired image
                            System.Console.WriteLine(string.Format("{0} {1}", acquiredImageInfo.PixelType, acquiredImageInfo.Resolution));
    
                            // dispose the acquired image
                            device.AcquiredImage.Dispose();
                            break;
    
                        case Vintasoft.Twain.AcquireModalState.ScanCompleted:
                            // output current state
                            System.Console.WriteLine("Scan completed.");
                            break;
    
                        case Vintasoft.Twain.AcquireModalState.ScanCanceled:
                            // output current state
                            System.Console.WriteLine("Scan canceled.");
                            break;
    
                        case Vintasoft.Twain.AcquireModalState.ScanFailed:
                            // output current state
                            System.Console.WriteLine(string.Format("Scan failed: {0}", device.ErrorString));
                            break;
                    }
                }
                while (acquireModalState != Vintasoft.Twain.AcquireModalState.None);
    
                // close the device
                device.Close();
    
                // close the device manager
                deviceManager.Close();
            }
        }
        catch (Vintasoft.Twain.TwainException ex)
        {
            System.Console.WriteLine("Error: " + ex.Message);
        }
    
        System.Console.ReadLine();
    }
    
    ''' <summary>
    ''' Synchronously acquire images from Kodak scanner and uses Kodak dual stream feature.
    ''' </summary>
    Public Sub SynchronouslyAcquireImagesFromKodakScannerAndUseDualStreamFeature()
            Try
                    Using deviceManager As New Vintasoft.Twain.DeviceManager()
                            ' open the device manager
                            deviceManager.Open()
    
                            ' get reference to the default device
                            Dim device As Vintasoft.Twain.Device = deviceManager.DefaultDevice
    
                            ' set scanning settings
                            device.TransferMode = Vintasoft.Twain.TransferMode.Memory
                            device.ShowUI = False
    
                            ' open the device
                            device.Open()
    
                            ' set inches as units of measure
                            device.UnitOfMeasure = Vintasoft.Twain.UnitOfMeasure.Inches
                            ' enable duplex
                            device.DocumentFeeder.DuplexEnabled = True
    
                            ' select color camera
                            device.Cameras.SetSelectedCamera("/Camera_Color_Both")
                            ' set resolution for color images
                            device.Resolution = New Vintasoft.Twain.Resolution(300, 300)
                            ' enable color camera
                            device.Cameras.EnableSelectedCamera()
    
                            ' select black-white camera
                            device.Cameras.SetSelectedCamera("/Camera_Bitonal_Both")
                            ' set resolution for black-white images
                            device.Resolution = New Vintasoft.Twain.Resolution(200, 200)
                            ' enable black-white camera
                            device.Cameras.EnableSelectedCamera()
    
                            ' synchronously acquire image(s) from TWAIN device
                            Dim acquireModalState As Vintasoft.Twain.AcquireModalState
                            Do
                                    acquireModalState = device.AcquireModal()
                                    Select Case acquireModalState
                                            Case Vintasoft.Twain.AcquireModalState.ImageAcquired
                                                    ' get info about acquired image
                                                    Dim acquiredImageInfo As Vintasoft.Twain.ImageInfo = device.AcquiredImage.ImageInfo
                                                    ' show message box with info about acquired image
                                                    System.Console.WriteLine(String.Format("{0} {1}", acquiredImageInfo.PixelType, acquiredImageInfo.Resolution))
    
                                                    ' dispose the acquired image
                                                    device.AcquiredImage.Dispose()
                                                    Exit Select
    
                                            Case Vintasoft.Twain.AcquireModalState.ScanCompleted
                                                    ' output current state
                                                    System.Console.WriteLine("Scan completed.")
                                                    Exit Select
    
                                            Case Vintasoft.Twain.AcquireModalState.ScanCanceled
                                                    ' output current state
                                                    System.Console.WriteLine("Scan canceled.")
                                                    Exit Select
    
                                            Case Vintasoft.Twain.AcquireModalState.ScanFailed
                                                    ' output current state
                                                    System.Console.WriteLine(String.Format("Scan failed: {0}", device.ErrorString))
                                                    Exit Select
                                    End Select
                            Loop While acquireModalState <> Vintasoft.Twain.AcquireModalState.None
    
                            ' close the device
                            device.Close()
    
                            ' close the device manager
                            deviceManager.Close()
                    End Using
            Catch ex As Vintasoft.Twain.TwainException
                    System.Console.WriteLine("Error: " + ex.Message)
            End Try
    
            System.Console.ReadLine()
    End Sub