VintaSoft Twain ActiveX v6.0
In This Topic
    How to skip blank pages while scanning
    In This Topic
    Blank pages can be skipped while scanning by 2 ways:
    1. using the scanner capabilities
    2. using the library (ActiveX) features

    1. Skipping of blank pages using the scanner capabilities

    For the beginning, it is necessary to check if the scanner supports the ability to skip blank pages - check if the scanner supports ICAP_AUTODISCARDBLANKPAGES capability.

    If the scanner supports that capability, then you need to set the value of the capability in a way to let the scanner skip blank pages or not.
    Valid values of the capability:

    Here is an example showing how to skip blank pages if the scanner supports this ability:
    Private VSTwain1 As New VintaSoftTwain()
    Private imageCount As Integer
    
    
    ''' <summary>
    ''' Scans images asynchronously.
    ''' </summary>
    Private Sub StartScan()
        ' open the device manager
        If Not VSTwain1.DeviceManager_Open() Then
            Console.WriteLine(VSTwain1.errorString)
            Exit Sub
        End If
        ' select device using standard device selection dialog
        VSTwain1.DeviceManager_ShowDefaultDeviceSelectionDialog()
    
        ' open the device
        If Not VSTwain1.Device_Open() Then
            Console.WriteLine(VSTwain1.errorString)
            Exit Sub
        End If
    
        ' specify that device UI must be shown
        VSTwain1.Device_ShowUI = True
    
        ' set settings of TIFF encoder
        VSTwain1.TiffEncoder_MultiPage = True
    
        ' set value of ICAP_AUTODISCARDBLANKPAGES to True
        VSTwain1.Device_Cap_Id = 4404  ' ICAP_AUTODISCARDBLANKPAGES
        VSTwain1.Device_Cap_ValueContainerType = DEVICECAPABILITYVALUECONTAINERTYPE.DEVICECAPABILITYVALUECONTAINERTYPE_OneValue
        VSTwain1.Device_Cap_Value = 1
        VSTwain1.Device_Cap_Set()
    
        ' subscribe to the device events
        AddHandler VSTwain1.DeviceImageAcquired, AddressOf VSTwain1_ImageAcquired
        AddHandler VSTwain1.DeviceScanCompleted, AddressOf VSTwain1_ScanCompleted
        AddHandler VSTwain1.DeviceScanFailed, AddressOf VSTwain1_ScanFailed
        AddHandler VSTwain1.DeviceScanCanceled, AddressOf VSTwain1_ScanCanceled
    
        ' acquire images asynchronously
        VSTwain1.Device_AcquireImage()
    End Sub
    
    Private Sub VSTwain1_ImageAcquired()
        ' get index of acquired image
        Dim imageIndex As Integer = VSTwain1.AcquiredImages_Count - 1
    
        ' save acquired image to TIFF file
        If Not VSTwain1.AcquiredImages_Save(imageIndex, Str(imageCount) + ".tif") Then
            Console.WriteLine(VSTwain1.errorString)
        End If
    End Sub
    
    Private Sub VSTwain1_ScanCompleted()
        Console.WriteLine("Scan is completed.")
    End Sub
    
    Private Sub VSTwain1_ScanFailed(errorString As String)
        Console.WriteLine(String.Format("Scan is failed: {0}.", errorString))
    End Sub
    
    Private Sub VSTwain1_ScanCanceled()
        Console.WriteLine("Scan is canceled.")
    End Sub


    Advantages of this technique:
    Disadvantages of this technique:


    2. Skipping of blank pages using the ActiveX features

    The algorithm of this technique is quite simple. The scanner sends to the library all images of acquired pages and the library checks if the image is blank using AcquiredImages_IsBlank method.

    Here is an example showing how to skip blank pages using IsBlank method:
    Private VSTwain1 As New VintaSoftTwain()
    
    
    ''' <summary>
    ''' Scans images asynchronously.
    ''' </summary>
    Private Sub StartScan()
        ' open the device manager
        If Not VSTwain1.DeviceManager_Open() Then
            Console.WriteLine(VSTwain1.errorString)
            Exit Sub
        End If
    
        ' select device using standard device selection dialog
        VSTwain1.DeviceManager_ShowDefaultDeviceSelectionDialog()
    
        ' specify that device UI must be shown
        VSTwain1.Device_ShowUI = True
    
        ' subscribe to the device events
        AddHandler VSTwain1.DeviceImageAcquired, AddressOf VSTwain1_ImageAcquired
        AddHandler VSTwain1.DeviceScanCompleted, AddressOf VSTwain1_ScanCompleted
        AddHandler VSTwain1.DeviceScanFailed, AddressOf VSTwain1_ScanFailed
        AddHandler VSTwain1.DeviceScanCanceled, AddressOf VSTwain1_ScanCanceled
    
        ' acquire images asynchronously
        VSTwain1.Device_AcquireImage()
    End Sub
    
    Private Sub VSTwain1_ImageAcquired()
        ' get index of acquired image
        Dim imageIndex As Integer = VSTwain1.AcquiredImages_Count - 1
    
        Dim currentNoiseLevel As Single
        ' if image is blank
        If VSTwain1.AcquiredImages_IsBlank(imageIndex, 0.01, currentNoiseLevel) Then
            Console.WriteLine("Image is blank.")
        Else
            If currentNoiseLevel = 100 Then
                Console.WriteLine("Image is not blank. " + VSTwain1.errorString)
            Else
                Console.WriteLine("Image is not blank. Noise level is " + Str(currentNoiseLevel) + "%")
            End If
        End If
    End Sub
    
    Private Sub VSTwain1_ScanCompleted()
        Console.WriteLine("Scan is completed.")
    End Sub
    
    Private Sub VSTwain1_ScanFailed(errorString As String)
        Console.WriteLine(String.Format("Scan is failed: {0}.", errorString))
    End Sub
    
    Private Sub VSTwain1_ScanCanceled()
        Console.WriteLine("Scan is canceled.")
    End Sub


    Advantages of this technique:
    Disadvantages of this technique: