VintaSoft Twain .NET SDK v10.2
How to get an extended information about image acquired from scanner?

VintaSoft Twain .NET SDK allows to retrieve the extended image information for acquired image. The extended image information can contain information about barcodes or patch codes found on a page, information about despeckle, deskew process and more.

You should proceed with the following steps if you want to retrieve the extended image information:

  1. Check that the retrieving of the extended image information is supported by the device.
  2. Choose which information you want to retrieve.
  3. Retrieve the extended image information about acquired image right after the image is acquired.

Example: Here is an example that shows how to retrieve barcodes found on image.
Imports System.Windows.Forms
Imports Vintasoft.Twain

Partial Public Class How_to_get_extended_information_about_acquired_image
    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.ScanFinished, New EventHandler(AddressOf device_ScanFinished)

            ' set scanning settings
            device1.TransferMode = TransferMode.Memory
            device1.ShowUI = False
            device1.DisableAfterAcquire = True

            ' open the device
            device1.Open()

            ' specify that image info is necessary
            device1.ExtendedImageInfo.Add(New ExtendedImageInfo(ExtendedImageInfoId.DocumentNumber))
            device1.ExtendedImageInfo.Add(New ExtendedImageInfo(ExtendedImageInfoId.PageNumber))
            device1.ExtendedImageInfo.Add(New ExtendedImageInfo(ExtendedImageInfoId.Camera))
            device1.ExtendedImageInfo.Add(New ExtendedImageInfo(ExtendedImageInfoId.FrameNumber))
            device1.ExtendedImageInfo.Add(New ExtendedImageInfo(ExtendedImageInfoId.Frame))
            device1.ExtendedImageInfo.Add(New ExtendedImageInfo(ExtendedImageInfoId.PixelFlavor))

            ' 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)
        ' output an extended information about the acquired image

        extendedImageInfoAboutAcquiredImageTextBox.Text += "IMAGE IS ACQUIRED" + Environment.NewLine
        extendedImageInfoAboutAcquiredImageTextBox.Text += Environment.NewLine

        Dim device As Device = DirectCast(sender, 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 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(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 TwainOneValueContainer = TryCast(info.Value, TwainOneValueContainer)
        If oneDeviceCapabilityValue IsNot Nothing Then
            extendedImageInfoAboutAcquiredImageTextBox.Text += String.Format("  Value={0}", oneDeviceCapabilityValue.Value)
            extendedImageInfoAboutAcquiredImageTextBox.Text += Environment.NewLine
        Else
            Dim arrayDeviceCapabilityValue As TwainArrayValueContainer = TryCast(info.Value, 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 Device = DirectCast(sender, Device)

        ' unsubscribe from device events
        RemoveHandler device1.ImageAcquired, New EventHandler(Of ImageAcquiredEventArgs)(AddressOf device_ImageAcquired)
        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_get_extended_information_about_acquired_image : Form
    {

        /// <summary>
        /// TWAIN device manager.
        /// </summary>
        DeviceManager _deviceManager;



        public How_to_get_extended_information_about_acquired_image()
        {
            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.ScanFinished += new EventHandler(device_ScanFinished);

                // set scanning settings
                device.TransferMode = TransferMode.Memory;
                device.ShowUI = false;
                device.DisableAfterAcquire = true;

                // open the device
                device.Open();

                // specify that image info is necessary
                device.ExtendedImageInfo.Add(new ExtendedImageInfo(ExtendedImageInfoId.DocumentNumber));
                device.ExtendedImageInfo.Add(new ExtendedImageInfo(ExtendedImageInfoId.PageNumber));
                device.ExtendedImageInfo.Add(new ExtendedImageInfo(ExtendedImageInfoId.Camera));
                device.ExtendedImageInfo.Add(new ExtendedImageInfo(ExtendedImageInfoId.FrameNumber));
                device.ExtendedImageInfo.Add(new ExtendedImageInfo(ExtendedImageInfoId.Frame));
                device.ExtendedImageInfo.Add(new ExtendedImageInfo(ExtendedImageInfoId.PixelFlavor));

                // 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)
        {
            // output an extended information about the acquired image

            extendedImageInfoAboutAcquiredImageTextBox.Text += "IMAGE IS ACQUIRED" + Environment.NewLine;
            extendedImageInfoAboutAcquiredImageTextBox.Text += Environment.NewLine;

            Device device = (Device)sender;
            for (int i = 0; i < device.ExtendedImageInfo.Count; i++)
            {
                AddExtendedImageInfoToResultTextBox(i, device.ExtendedImageInfo[i]);
            }
            extendedImageInfoAboutAcquiredImageTextBox.Text += 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, ExtendedImageInfo info)
        {
            if (!info.IsValueValid)
                return;

            extendedImageInfoAboutAcquiredImageTextBox.Text += string.Format("Extended image info {0}", index);
            extendedImageInfoAboutAcquiredImageTextBox.Text += Environment.NewLine;

            extendedImageInfoAboutAcquiredImageTextBox.Text += string.Format("  Name={0}", Enum.GetName(typeof(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;

            TwainOneValueContainer oneDeviceCapabilityValue = info.Value as TwainOneValueContainer;
            if (oneDeviceCapabilityValue != null)
            {
                extendedImageInfoAboutAcquiredImageTextBox.Text += string.Format("  Value={0}", oneDeviceCapabilityValue.Value);
                extendedImageInfoAboutAcquiredImageTextBox.Text += Environment.NewLine;
            }
            else
            {
                TwainArrayValueContainer arrayDeviceCapabilityValue = info.Value as 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 += Environment.NewLine;
                }
            }
        }
        
        /// <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.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.");
        }

    }
}