Click or drag to resize

AcquisitionFileTransfer Event

This event will fire just before acquiring an image directly to file. You must fill in the FileName property of the FileTransferEventArgs object.

Namespace:  Atalasoft.Twain
Assembly:  Atalasoft.DotTwain (in Atalasoft.DotTwain.dll) Version: 11.4.0.9.0.377 (.NET 4.5.2, x86)
Syntax
public event FileTransferEventHandler FileTransfer

Value

Type: Atalasoft.TwainFileTransferEventHandler
Remarks
You can cancel the acquisition by setting the CancelPending property of the FileTransferEventArgs to true.
Examples
Scan to file (C#)
// Create an instance of Acquisition and set the FileTransfer event.
Acquisition acquisition = new Acquisition(this);
acquisition.FileTransfer += new FileTransferEventHandler(OnFileTransfer);

// We use the AcquireFinished event to know when to close the device.
acquisition.AcquireFinished += new System.EventHandler(OnAcquireFinished);

// The call is asynchronous, so hold onto the device object.
Device dev = null;

// A count variable used to create unique filenames.
int fileCount = 0;

private void AcquireImageToFile()
{
    // We are going to acquire from the default device.
    this.dev = this.acquisition.Devices.Default;

    // You have to open the device before you can get property values.
    this.dev.Open();

    // See if the device supports the TIFF format.
    SourceFileFormats[] formats = this.dev.GetSupportedImageFormats();
    bool canSaveToFile = false;

    foreach(SourceFileFormats format in formats) {
        if (format == SourceFileFormats.Tiff)
        {
            // Tell the device which format to use.
            this.dev.FileFormat = format;
            canSaveToFile = true;
            break;
        }
    }

    if (canSaveToFile == false)
    {
        // Be sure to close the device connection.
        this.dev.Close();
        MessageBox.Show(this, "This device doesn't allow saving to TIFF.");
        return;
    }

    // Acquire the image to file.
    this.dev.Acquire(false, true);
}

private void OnFileTransfer(object sender, FileTransferEventArgs e)
{
    // Set the filename for this image.
    fileCount++;
    e.FileName = imageFolder + "image" + fileCount.ToString() + ".tif";
}

private void OnAcquireFinished(object sender, System.EventArgs e)
{
    // Do not forget to close the device.
    if (this.dev != null)
        this.dev.Close();
}
Scan to file (Visual Basic)
' Create an instance of Acquisition and set the FileTransfer event.
Dim acquisition As Acquisition = New Acquisition(Me) 
acquisition.FileTransfer += New FileTransferEventHandler(OnFileTransfer)

' We use the AcquireFinished event to know when to close the device.
acquisition.AcquireFinished += New System.EventHandler(OnAcquireFinished)

' The call is asynchronous, so hold onto the device object.
Dim dev As Device = Nothing 

' A count variable used to create unique filenames.
Dim fileCount As Integer =  0 

Private  Sub AcquireImageToFile()
    ' We are going to acquire from the default device.
    Me.dev = Me.acquisition.Devices.Default

    ' You have to open the device before you can get property values.
    Me.dev.Open()

    ' See if the device supports the TIFF format.
    Dim formats() As SourceFileFormats = Me.dev.GetSupportedImageFormats() 
    Dim canSaveToFile As Boolean = False 

    Dim Format As SourceFileFormats
    For Each Format In formats
        If Format = SourceFileFormats.Tiff Then
            ' Tell the device which format to use.
            Me.dev.FileFormat = Format
            canSaveToFile = True
            Exit For
        End If
    Next

    If canSaveToFile = False Then
        ' Be sure to close the device connection.
        Me.dev.Close()
        MessageBox.Show(this, "This device doesn't allow saving to TIFF.")
        Return
    End If

    ' Acquire the image to file.
    Me.dev.Acquire(False, True)
End Sub

Private  Sub OnFileTransfer(ByVal sender As Object, ByVal e As FileTransferEventArgs)
    ' Set the filename for this image.
    fileCount = fileCount + 1
    e.FileName = imageFolder & "image" & fileCount.ToString() & ".tif"
End Sub

Private  Sub OnAcquireFinished(ByVal sender As Object, ByVal e As System.EventArgs)
    ' Do not forget to close the device.
    If Not Me.dev Is Nothing Then
        Me.dev.Close()
    End If
End Sub
See Also