VintaSoft Twain ActiveX v6.0
In This Topic
    Acquire images directly to disk
    In This Topic

    A lot of TWAIN scanning devices support the File transfer mode and allow to save acquired images directly to disk.
    Transfer modes supported by device can be retrieved via Device_GetSupportedTransferModes method.

    A lot of TWAIN scanning devices can save acquired images as BMP files. Advanced devices can save acquired images as TIFF, JPEG, PDF, etc files.
    File formats supported by device can be retrieved via Device_GetSupportedImageFileFormats method.
    File format compressions supported by device can be retrieved via Device_GetSupportedImageCompressions method.


    Example: Here is an example that shows how to save acquired images directly to a disk as JPEG files with image quality value 70%.

    Private VSTwain1 As New VintaSoftTwain()
    Private imageCount As Integer
    
    
    ''' <summary>
    ''' Scans images asynchronously.
    ''' </summary>
    Private Sub ScanImages()
        ' open the device manager
        If Not VSTwain1.DeviceManager_Open() Then
            Console.WriteLine(VSTwain1.errorString)
            Exit Sub
        End If
    
        ' open the device
        If Not VSTwain1.Device_Open Then
            Console.WriteLine(VSTwain1.errorString)
            Exit Sub
        End If
    
        ' scan images without UI
        VSTwain1.Device_ShowUI = False
    
        ' specify that device must save acquired images directly to disk
        VSTwain1.Device_TransferMode = TRANSFERMODE.TRANSFERMODE_File
        ' specify that acquired images must be save as JPEG files
        VSTwain1.Device_FileFormat = TWAINIMAGEFILEFORMAT.TWAINIMAGEFILEFORMAT_Jpeg
        ' specify the quality of JPEG images
        VSTwain1.Device_FileJpegQuality = 70
        ' initialize the image count
        imageCount = 1
        ' specify the name of file where acquired image must be saved
        VSTwain1.Device_FileName = Str(imageCount) + ".jpg"
    
        ' 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()
        ' increment the image count
        imageCount = imageCount + 1
        ' specify the name of file where acquired image must be saved
        VSTwain1.Device_FileName = Str(imageCount) + ".jpg"
    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