OpenScanner Example VB

This example uses SetScanCapability to specify the Image Type for scanning, without using the scanner's TWAIN dialog box.

Private Sub cmdSetImgType_Click()
    'User is given the option to select an Image Type for scanning
    'of black and white, grayscale or color. The option selected
    'is stored in the global variable ScanType.
    Const IT_BW = 1
    Const IT_GRAY8 = 4
    Const IT_RGB = 16
    Const CAP_SCAN_IMAGE_TYPE = 100
    Const CAP_SCAN_IMAGE_TYPES_SUPPORTED = 1
    Dim varScanImgType As Variant
    'Global Scantype as integer 
    'Scanner must be open for Capability check.
    ImgScan1.OpenScanner 
    'See what image types the scanner supports.
    varScanImgType = 
        ImgScan1.GetScanCapability(CAP_SCAN_IMAGE_TYPES_SUPPORTED)
    If VarType(varScanImgType) = vbError Then
        MsgBox "Unable to get Supported Image Types"
    End If 
    'Find out if the type the user selected is supported;
    'if so set the capability to that image type
    Select Case ScanType
    Case 1
        If varScanImgType And IT_BW Then
           ImgScan1.SetScanCapability CAP_SCAN_IMAGE_TYPE, IT_BW
        Else
           MsgBox "Black & White image type is not supported by your scanner"
        End If
    Case 2
        If varScanImgType And IT_GRAY8 Then
           ImgScan1.SetScanCapability CAP_SCAN_IMAGE_TYPE, IT_GRAY8
        Else
           MsgBox "Grayscale image type is not supported by your scanner"
        End If
    Case 3
        If varScanImgType And IT_RGB Then
           ImgScan1.SetScanCapability CAP_SCAN_IMAGE_TYPE, IT_RGB
        Else
           MsgBox "Color image type is not supported by your scanner"
        End If
    End Select
End Sub