ImageMan ActiveX
Setting and Getting Scanner Capabilities

The TWAIN specification defines a series of capabilties that scanners can implement. Capabilities are used to enable and disable various options of the scanner or camera device. Options like Duplex scanning, brightness, contrast, resolution, page size are all specified using the scanner's capabilities.

 

The Twain control allows your application to query and set capabilities using the SetCapability, NegotiateCapability and GetCapability methods. Most applications will use the NegotiateCapability method for setting capabilities as it does so with the least amount of code. Applications that need lower level control can utilize the GetCapability and SetCapability methods. For instance an application that wishes to provide its own scanning dialog displaying supported resolutions and color formats would need to use the GetCapabilities method to query the scanners support resolutions and color formats.

 

Using NegotiateCapability

When setting capabilities that have many possible values such as Resolution or Contrast, it important to specify a value that's supported by the scanner. Generally this would require a call to GetCapability to find out the supported values and then a call to SetCapability to set the value. The NegotiateCapability method simplifies this process by doing these calls internally and selecting the value closest to that passed to the method.

 

' Set brightness to +100

if IMTwain1.NegotiateCapability( Capability.Brightness, 100 ) Then

' Brightness set OK

else

' Set Failed - ImTwain1.LastError.Description contains a description of the error

End if

 

Using GetCapability

The GetCapability method allows an application to query a scanner for a certain capability. For instance an application can query a scanner for the supported resolutions or the color depths supported. The method returns the results of querying the capability in a variant. The returned variant may contain a string or numeric value or an object such as Enumeration or Range. The Enumeration and Range objects are used to return multiple values. The Enumeration object contains a collection of variants representing each supported value. The Range object is used to return values which are defined in a specific range i.e. from 0 to 1000 in increments of 1. If a capability isn't supported by a given scanner then this method will return false.

 

    Dim var As Variant
    Dim lDataType As Long
   
    retval = ImTwain1.GetCapability(ImTwain80Ctl.Capabilities.Pixel_Flavor, var, lDataType)
   
    If retval Then

        ' GetCapability can return an Enumeration object, Range object or a single value in the variant 
        If VarType(var) = vbObject Then
           If TypeName(var) = "Enumeration" Then    ' Handle an Enumeration object
                Dim em As Enumeration
                Set em = var
                Debug.Print "Enum Contains " & em.ItemCount
                Debug.Print "Current = " & em.Current
                Debug.Print "Default = " & em.Default
               
                For Each v In em.Items
                    Debug.Print v
                Next
            ElseIf TypeName(var) = "Range" Then      ' Handle a Range object
                Dim rg As Range
                Set rg = var
                Debug.Print "Range Type is " & rg.DataType
                Debug.Print "Min = " & rg.Min
                Debug.Print "Max = " & rg.Max
                Debug.Print "Step = " & rg.Step
                Debug.Print "Default = " & rg.Default
            End If
        Else
            Debug.Print "Value = " & var                     ' The variant is just a single value
        End If
    End If

Using SetCapability

The SetCapability method allows an application to specify a value for a given capability. If the method fails it will return False and the LastError object will contain details of the error.

 

' Set brightness to +100

if IMTwain1.SetCapability( Capability.Brightness, 100 ) Then

' Brightness set OK

else

' Set Failed - ImTwain1.LastError.Description contains a description of the error

End if

 

 

 


© 2014 Data Techniques, Inc. All rights reserved.

Submit feedback on this topic