VintaSoft Twain .NET SDK v10.2
In This Topic
    How to use the Dual Stream feature of Kodak scanner?
    In This Topic

    SDK allows to use the Dual Stream feature of Kodak scanners.

    Dual Stream feature means that scanner has some "cameras" and can make some snapshots of each acquired page. Each camera has predefined settings (pixel type and page side) and customizable settings (resolution, brightness, contrast, threshold, filters, etc).

    For example, most of Kodak scanners has 6 cameras:



    Example: Here is an example that shows how to acquire both sides of page as black-white and color images with different resolutions.
    Imports System.Windows.Forms
    Imports Vintasoft.Twain
    
    Partial Public Class How_to_use_Dual_Stream_feature_of_Kodak_scanner
        Inherits Form
    
        ''' <summary>
        ''' TWAIN device manager.
        ''' </summary>
        Private _deviceManager As DeviceManager
    
    
    
        Public Sub New()
            InitializeComponent()
    
            ' create and open device manager
            _deviceManager = New DeviceManager(Me)
            _deviceManager.Open()
        End Sub
    
    
    
        ''' <summary>
        ''' Acquire images asynchronously.
        ''' </summary>
        Public Sub AcquireImagesAsynchronously()
            Try
                ' get reference to the default device
                Dim device1 As Device = _deviceManager.DefaultDevice
    
                ' subscribe to the device events
                AddHandler device1.ImageAcquired, New EventHandler(Of ImageAcquiredEventArgs)(AddressOf device_ImageAcquired)
                AddHandler device1.ScanCanceled, New EventHandler(AddressOf device_ScanCanceled)
                AddHandler device1.ScanFailed, New EventHandler(Of ScanFailedEventArgs)(AddressOf device_ScanFailed)
                AddHandler device1.ScanFinished, New EventHandler(AddressOf device_ScanFinished)
    
                ' set scanning settings
                device1.TransferMode = TransferMode.Memory
                device1.ShowUI = False
    
                ' open the device
                device1.Open()
                ' set inches as units of measure
                device1.UnitOfMeasure = UnitOfMeasure.Inches
                ' enable duplex
                device1.DocumentFeeder.DuplexEnabled = True
    
                ' select color camera
                device1.Cameras.SetSelectedCamera("/Camera_Color_Both")
                ' set resolution for color images
                device1.Resolution = New Resolution(300, 300)
                ' enable color camera
                device1.Cameras.EnableSelectedCamera()
    
                ' select black-white camera
                device1.Cameras.SetSelectedCamera("/Camera_Bitonal_Both")
                ' set resolution for black-white images
                device1.Resolution = New Resolution(200, 200)
                ' enable black-white camera
                device1.Cameras.EnableSelectedCamera()
    
                ' acquire images asynchronously
                device1.Acquire()
            Catch ex As 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)
            ' get info about acquired image
            Dim acquiredImageInfo As ImageInfo = e.Image.ImageInfo
            ' show message box with info about acquired image
            MessageBox.Show(String.Format("{0} {1}", acquiredImageInfo.PixelType, acquiredImageInfo.Resolution))
    
            ' dispose the acquired image
            e.Image.Dispose()
        End Sub
    
        ''' <summary>
        ''' Scan is canceled.
        ''' </summary>
        Private Sub device_ScanCanceled(ByVal sender As Object, ByVal e As EventArgs)
            MessageBox.Show("Scan is canceled.")
        End Sub
    
        ''' <summary>
        ''' Scan is failed.
        ''' </summary>
        Private Sub device_ScanFailed(ByVal sender As Object, ByVal e As Vintasoft.Twain.ScanFailedEventArgs)
            MessageBox.Show("Scan is failed: " + Convert.ToString(e.ErrorString))
        End Sub
    
        ''' <summary>
        ''' Scan is finished.
        ''' </summary>
        Private Sub device_ScanFinished(ByVal sender As Object, ByVal e As EventArgs)
            Dim device1 As Device = DirectCast(sender, Device)
    
            ' unsubscribe from device events
            RemoveHandler device1.ImageAcquired, New EventHandler(Of ImageAcquiredEventArgs)(AddressOf device_ImageAcquired)
            RemoveHandler device1.ScanCanceled, New EventHandler(AddressOf device_ScanCanceled)
            RemoveHandler device1.ScanFailed, New EventHandler(Of ScanFailedEventArgs)(AddressOf device_ScanFailed)
            RemoveHandler device1.ScanFinished, New EventHandler(AddressOf device_ScanFinished)
    
            ' if device is not closed
            If device1.State <> DeviceState.Closed Then
                ' close the device
                device1.Close()
            End If
    
            MessageBox.Show("Scan is finished.")
        End Sub
    
    End Class
                  
    
    using System;
    using System.Windows.Forms;
    using Vintasoft.Twain;
    
    namespace TwainExamples_CSharp
    {
        public partial class How_to_use_Dual_Stream_feature_of_Kodak_scanner : Form
        {
    
            /// <summary>
            /// TWAIN device manager.
            /// </summary>
            DeviceManager _deviceManager;
    
    
    
            public How_to_use_Dual_Stream_feature_of_Kodak_scanner()
            {
                InitializeComponent();
    
                // create and open device manager
                _deviceManager = new DeviceManager(this);
                _deviceManager.Open();
            }
    
    
    
            /// <summary>
            /// Acquire images asynchronously.
            /// </summary>
            public void AcquireImagesAsynchronously()
            {
                try
                {
                    // get reference to the default device
                    Device device = _deviceManager.DefaultDevice;
    
                    // subscribe to the device events
                    device.ImageAcquired += new EventHandler(device_ImageAcquired);
                    device.ScanCanceled += new EventHandler(device_ScanCanceled);
                    device.ScanFailed += new EventHandler(device_ScanFailed);
                    device.ScanFinished += new EventHandler(device_ScanFinished);
    
                    // set scanning settings
                    device.TransferMode = TransferMode.Memory;
                    device.ShowUI = false;
                   
                    // open the device
                    device.Open();
                    // set inches as units of measure
                    device.UnitOfMeasure = 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 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 Resolution(200, 200);
                    // enable black-white camera
                    device.Cameras.EnableSelectedCamera();
    
                    // acquire images asynchronously
                    device.Acquire();
                }
                catch (TwainException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
    
            /// <summary>
            /// Image is acquired.
            /// </summary>
            private void device_ImageAcquired(object sender, Vintasoft.Twain.ImageAcquiredEventArgs e)
            {
                // get info about acquired image
                ImageInfo acquiredImageInfo = e.Image.ImageInfo;
                // show message box with info about acquired image
                MessageBox.Show(string.Format("{0} {1}", acquiredImageInfo.PixelType, acquiredImageInfo.Resolution));
    
                // dispose the acquired image
                e.Image.Dispose();
            }
    
            /// <summary>
            /// Scan is canceled.
            /// </summary>
            private void device_ScanCanceled(object sender, EventArgs e)
            {
                MessageBox.Show("Scan is canceled.");
            }
    
            /// <summary>
            /// Scan is failed.
            /// </summary>
            private void device_ScanFailed(object sender, Vintasoft.Twain.ScanFailedEventArgs e)
            {
                MessageBox.Show("Scan is failed: " + e.ErrorString);
            }
    
            /// <summary>
            /// Scan is finished.
            /// </summary>
            void device_ScanFinished(object sender, EventArgs e)
            {
                Device device = (Device)sender;
    
                // unsubscribe from device events
                device.ImageAcquired -= new EventHandler(device_ImageAcquired);
                device.ScanCanceled -= new EventHandler(device_ScanCanceled);
                device.ScanFailed -= new EventHandler(device_ScanFailed);
                device.ScanFinished -= new EventHandler(device_ScanFinished);
    
                // if device is not closed
                if (device.State != DeviceState.Closed)
                    // close the device
                    device.Close();
    
                MessageBox.Show("Scan is finished.");
            }
        }
    }