VintaSoft Twain .NET SDK v10.2
ExtendedImageInfoCollection Class
Members  Example 




Vintasoft.Twain Namespace : ExtendedImageInfoCollection Class
Class that allows to extract extended information about acquired image.
Object Model
ExtendedImageInfoCollection ClassExtendedImageInfo Class
Syntax
'Declaration
 
<DefaultMemberAttribute("Item")>
Public NotInheritable Class ExtendedImageInfoCollection 
   Inherits System.Collections.CollectionBase
'Usage
 
Dim instance As ExtendedImageInfoCollection
[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 
Example
This example shows how to get information about barcodes found on acquired image.
Public Sub GetExtendedImageInfo()
    Using deviceManager As New DeviceManager()
        Try
            ' open the device manager
            deviceManager.Open()
            
            deviceManager.ShowDefaultDeviceSelectionDialog()
            
            ' get reference to the default device
            Dim device As Device = deviceManager.DefaultDevice
            
            ' specify that device UI must not be used
            device.ShowUI = False
            ' specify that device must be closed after scan
            device.DisableAfterAcquire = True
            
            ' open the device
            device.Open()
            
            ' specify that image info is necessary
            device.ExtendedImageInfo.Add(New ExtendedImageInfo(ExtendedImageInfoId.BarcodeCount))
            device.ExtendedImageInfo.Add(New ExtendedImageInfo(ExtendedImageInfoId.BarcodeType))
            device.ExtendedImageInfo.Add(New ExtendedImageInfo(ExtendedImageInfoId.BarcodeTextLength))
            device.ExtendedImageInfo.Add(New ExtendedImageInfo(ExtendedImageInfoId.BarcodeText))
            
            ' acquire images from device
            Dim acquireModalState1 As AcquireModalState = AcquireModalState.None
            Do
                acquireModalState1 = device.AcquireModal()
            
                Select Case acquireModalState1
                    Case AcquireModalState.ImageAcquired
            
                        ' get information about barcode count
                        Dim barcodeCountInfo As ExtendedImageInfo = device.ExtendedImageInfo(0)
                        ' if value is valid
                        If barcodeCountInfo.IsValueValid Then
                            ' get container of value
                            Dim valueContainer As TwainValueContainerBase = barcodeCountInfo.Value
                            Dim oneValueContainer As TwainOneValueContainer = TryCast(valueContainer, TwainOneValueContainer)
                            ' if container is valid
                            If oneValueContainer IsNot Nothing Then
                                ' get barcode count
                                Dim barcodeCountValue As Integer = CInt(oneValueContainer.GetAsUInt32())
            
                                ' get information about barcode type and text
                                Dim barcodeTypeInfo As ExtendedImageInfo = device.ExtendedImageInfo(1)
                                Dim barcodeTextLengthInfo As ExtendedImageInfo = device.ExtendedImageInfo(2)
                                Dim barcodeTextInfo As ExtendedImageInfo = device.ExtendedImageInfo(3)
            
                                Dim infoString As String
            
                                ' if barcode is found
                                If barcodeCountValue = 1 Then
                                    ' add information about barcode type to the info string
                                    If barcodeTypeInfo.IsValueValid Then
                                        Dim barcodeTypeValue As TwainOneValueContainer = TryCast(barcodeTypeInfo.Value, TwainOneValueContainer)
                                        infoString = "BarcodeType=" + barcodeTypeValue.Value + " "
                                    Else
                                        infoString = "BarcodeType=Undefined "
                                    End If
            
                                    ' add information about barcode text to the info string
                                    If barcodeTextInfo.IsValueValid Then
                                        Dim barcodeTextValue As TwainOneValueContainer = TryCast(barcodeTextInfo.Value, TwainOneValueContainer)
                                        infoString = "BarcodeText='" + barcodeTextValue.Value + "'"
                                    Else
                                        infoString = "BarcodeText=Undefined "
                                    End If
            
                                    ' write barcode info to the console
                                    Console.WriteLine(infoString)
                                Else
                                    ' if barcodes are found
                                    For i As Integer = 0 To barcodeCountValue - 1
                                        ' add information about barcode type to the info string
                                        If barcodeTypeInfo.IsValueValid Then
                                            Dim barcodeTypeValue As TwainArrayValueContainer = TryCast(barcodeTypeInfo.Value, TwainArrayValueContainer)
                                            infoString = "BarcodeType=" + barcodeTypeValue.Values.GetValue(i) + " "
                                        Else
                                            infoString = "BarcodeType=Undefined "
                                        End If
            
                                        ' add information about barcode text to the info string
                                        If barcodeTextInfo.IsValueValid Then
                                            Dim barcodeTextValue As TwainArrayValueContainer = TryCast(barcodeTextInfo.Value, TwainArrayValueContainer)
                                            infoString = "BarcodeText='" + barcodeTextValue.Values.GetValue(i) + "'"
                                        Else
                                            infoString = "BarcodeText=Undefined "
                                        End If
            
                                        ' write barcode info to the console
                                        Console.WriteLine(infoString)
                                    Next
                                End If
                            End If
                        End If
            
                        ' if acquired image is present (Native or Memory transfer mode is used)
                        If device.AcquiredImage IsNot Nothing Then
                            ' dispose the acquired image
                            device.AcquiredImage.Dispose()
                        End If
            
                        Exit Select
                End Select
            Loop While acquireModalState1 <> AcquireModalState.None
            
            ' close the device
            device.Close()
            
            ' close the device manager
            deviceManager.Close()
        Catch ex As TwainException
            Console.WriteLine("Error: " + ex.Message)
            Console.ReadLine()
        End Try
    End Using
End Sub
public void GetExtendedImageInfo()
{
    using (DeviceManager deviceManager = new DeviceManager())
    {
        try
        {
            // open the device manager
            deviceManager.Open();
            
            deviceManager.ShowDefaultDeviceSelectionDialog();
            
            // get reference to the default device
            Device device = deviceManager.DefaultDevice;
            
            // specify that device UI must not be used
            device.ShowUI = false;
            // specify that device must be closed after scan
            device.DisableAfterAcquire = true;
            
            // open the device
            device.Open();
            
            // specify that image info is necessary
            device.ExtendedImageInfo.Add(new ExtendedImageInfo(ExtendedImageInfoId.BarcodeCount));
            device.ExtendedImageInfo.Add(new ExtendedImageInfo(ExtendedImageInfoId.BarcodeType));
            device.ExtendedImageInfo.Add(new ExtendedImageInfo(ExtendedImageInfoId.BarcodeTextLength));
            device.ExtendedImageInfo.Add(new ExtendedImageInfo(ExtendedImageInfoId.BarcodeText));
            
            // acquire images from device
            AcquireModalState acquireModalState = AcquireModalState.None;
            do
            {
                acquireModalState = device.AcquireModal();
            
                switch (acquireModalState)
                {
                    case AcquireModalState.ImageAcquired:
            
                        // get information about barcode count
                        ExtendedImageInfo barcodeCountInfo = device.ExtendedImageInfo[0];
                        // if value is valid
                        if (barcodeCountInfo.IsValueValid)
                        {
                            // get container of value
                            TwainValueContainerBase valueContainer = barcodeCountInfo.Value;
                            TwainOneValueContainer oneValueContainer = valueContainer as TwainOneValueContainer;
                            // if container is valid
                            if (oneValueContainer != null)
                            {
                                // get barcode count
                                int barcodeCountValue = (int)oneValueContainer.GetAsUInt32();
            
                                // get information about barcode type and text
                                ExtendedImageInfo barcodeTypeInfo = device.ExtendedImageInfo[1];
                                ExtendedImageInfo barcodeTextLengthInfo = device.ExtendedImageInfo[2];
                                ExtendedImageInfo barcodeTextInfo = device.ExtendedImageInfo[3];
            
                                string infoString;
            
                                // if barcode is found
                                if (barcodeCountValue == 1)
                                {
                                    // add information about barcode type to the info string
                                    if (barcodeTypeInfo.IsValueValid)
                                    {
                                        TwainOneValueContainer barcodeTypeValue = barcodeTypeInfo.Value as TwainOneValueContainer;
                                        infoString = "BarcodeType=" + barcodeTypeValue.Value + " ";
                                    }
                                    else
                                        infoString = "BarcodeType=Undefined ";
            
                                    // add information about barcode text to the info string
                                    if (barcodeTextInfo.IsValueValid)
                                    {
                                        TwainOneValueContainer barcodeTextValue = barcodeTextInfo.Value as TwainOneValueContainer;
                                        infoString = "BarcodeText='" + barcodeTextValue.Value + "'";
                                    }
                                    else
                                        infoString = "BarcodeText=Undefined ";
            
                                    // write barcode info to the console
                                    Console.WriteLine(infoString);
                                }
                                // if barcodes are found
                                else
                                {
                                    for (int i = 0; i < barcodeCountValue; i++)
                                    {
                                        // add information about barcode type to the info string
                                        if (barcodeTypeInfo.IsValueValid)
                                        {
                                            TwainArrayValueContainer barcodeTypeValue = barcodeTypeInfo.Value as TwainArrayValueContainer;
                                            infoString = "BarcodeType=" + barcodeTypeValue.Values.GetValue(i) + " ";
                                        }
                                        else
                                            infoString = "BarcodeType=Undefined ";
            
                                        // add information about barcode text to the info string
                                        if (barcodeTextInfo.IsValueValid)
                                        {
                                            TwainArrayValueContainer barcodeTextValue = barcodeTextInfo.Value as TwainArrayValueContainer;
                                            infoString = "BarcodeText='" + barcodeTextValue.Values.GetValue(i) + "'";
                                        }
                                        else
                                            infoString = "BarcodeText=Undefined ";
            
                                        // write barcode info to the console
                                        Console.WriteLine(infoString);
                                    }
                                }
                            }
                        }
            
                        // if acquired image is present (Native or Memory transfer mode is used)
                        if (device.AcquiredImage != null)
                            // dispose the acquired image
                            device.AcquiredImage.Dispose();
            
                        break;
                }
            }
            while (acquireModalState != AcquireModalState.None);
            
            // close the device
            device.Close();
            
            // close the device manager
            deviceManager.Close();
        }
        catch (TwainException ex)
        {
            Console.WriteLine("Error: " + ex.Message);
            Console.ReadLine();
        }
    }
}
Inheritance Hierarchy

System.Object
   System.Collections.CollectionBase
      Vintasoft.Twain.ExtendedImageInfoCollection

Requirements

Target Platforms: Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

See Also

Reference

ExtendedImageInfoCollection Members
Vintasoft.Twain Namespace