AcquireFast2 Method

Summary

(Document/Medical only) Acquires one or more images from a TWAIN source and stores the images in the specified file(s).

Syntax
C#
VB
C++
Public Sub AcquireFast2( _ 
   ByVal baseFileName As String, _ 
   ByVal startupPageNumber As Integer, _ 
   ByVal flags As TwainFastUserInterfaceFlags, _ 
   ByVal transferMode As TwainTransferMode, _ 
   ByVal format As RasterImageFormat, _ 
   ByVal bitsPerPixel As Integer, _ 
   ByVal multiPage As Boolean, _ 
   ByVal bufferSize As Integer, _ 
   ByVal usePreferredBufferSize As Boolean _ 
)  

Parameters

baseFileName
The base name of the image file to which to save the acquired data.

startupPageNumber
The starting page number where the numbering of the newly scanned files names starts. For example, if this parameter has the value 3, then the scanned files will have the name "BaseFileName_0003.bmp".

Pass -1 for this parameter to start numbering files from page 1. In this case, the first scanned file will have the file name "BaseFileName_0001.bmp".

flags
Flag that indicates whether to display the manufacturer's user interface.

transferMode
The transfer mode used to acquire.

format
The image format used to acquire.

bitsPerPixel
Represents the BitsPerPixel used to acquire.

multiPage
true for multipage acquire; false for single page.

bufferSize
Specifies the buffer size (in bytes) used to acquire images.

usePreferredBufferSize
Specifies whether to use the preferred buffer size specified by the TWAIN driver.

true to use the preferred buffer size specified by the TWAIN driver; false to use the user-defined buffer size (bufferSize parameter).

Remarks

AcquireFast and AcquireFast2 are similar to the Acquire method. All are used to acquire one or more images. However, both AcquireFast and AcquireFast2 acquire one or more images and save them to one or more files.

AcquireFast2 was added in order to allow users to prevent already scanned files from being overwritten by a subsequent scan batch. To prevent such over-writing, specify the starting page number (startupPageNumber) for the new files being created to skip over the files that already exist. For example, suppose three pages have been scanned and the specified baseFileName parameter was "BaseFileName.bmp". The names for the output files will be "BaseFileName_0001.bmp", "BaseFileName_0002.bmp" and "BaseFileName_0003.bmp". Now suppose a new scan begins and the startupPageNumber is set to -1 (page numbering starts at 1). Under these conditions, the files that have already been saved will be overwritten. To avoid that, pass 4 for the startupPageNumber parameter so the new scanned files will start from 4 as "BaseFileName_0004.bmp", then "BaseFileName_0005.bmp", etc.

There are two ways to set the scanning configuration. The first way is to determine the configuration before calling AcquireFast2, by calling the FindFastConfiguration method to determine the best scan configuration. The second way is to let AcquireFast2 determine the best method for you.

Note: In fact, if you do not call the FindFastConfiguration method before calling the AcquireFast2 method, then the AcquireFast2 method will determine the best/fastest scanning method to use, based on the type of scanner being used.

The format, baseFileName, and multiPage parameters determine how the images are saved, as follows:

  • If the file format set in the format parameter does not support multipage files, AcquireFast2 will ignore the multiPage parameter and automatically save the scanned images to separate files. The files are named by appending numbers to the string used for the baseFileName. For example, if the string in baseFileName is "Temp.jpg", the method will append the number of the image (0001, 0002, etc.), to the name of the file. Therefore, the output file names will be "Temp0001.jpg", "Temp0002.jpg", etc.

  • If the file format specified in the format parameter supports multipage files, this method will use the multiPage parameter to determine how to save multiple images.

    • If multiPage is set to false, each scanned page will be saved to a separate file, named in the same manner described in the previous paragraph.
    • If multiPage is set to true, the name of the output file will be the exact string specified in baseFileName (Temp.jpg), and it will be saved as a multipage file.

To use the AcquireMultiPage event, set the EnableAcquireMultiPageEvent property value to true before calling the AcquireFast2 method. The AcquireMultiPage event will be fired twice for each scanned page: the first time when the TWAIN source begins scanning the page, and again when the TWAIN source has finished scanning the page. For more information, refer to How to Acquire from the Twain Source.

For more information, refer to Fast TWAIN (Scan Configurations).

Example
C#
VB
using Leadtools; 
using Leadtools.Twain; 
 
public void twain_AcquireMulti2(object sender, TwainAcquireMultiPageEventArgs e) 
{ 
   string msg; 
 
   if (e.FinishScan) 
   { 
      msg = String.Format("The page # {0} is scanned and saved to file name {1}", e.PageNumber, e.FileName); 
      MessageBox.Show(msg); 
   } 
 
   e.Cancel = false; 
} 
 
public void AcquireFast2Example(IntPtr parent) 
{ 
   TwainSession session = new TwainSession(); 
   session.Startup(parent, "manufacturer", "productFamily", "version", "application", TwainStartupFlags.None); 
 
   session.EnableAcquireMultiPageEvent = true; 
   session.AcquireMultiPage += new EventHandler<TwainAcquireMultiPageEventArgs>(twain_AcquireMulti2); 
 
   session.AcquireFast2(Path.Combine(LEAD_VARS.ImagesDir, "Out_test.tif"), 
                       3, // start page number to use when numbering output file names, output files should be test_0003.tif, test_0004.tif, ...etc 
                       TwainFastUserInterfaceFlags.Show, 
                       TwainTransferMode.Buffer, 
                       RasterImageFormat.Tif, 1, true, 0, true); 
   session.Shutdown(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; 
} 
Imports Leadtools 
Imports Leadtools.Twain 
 
Public Sub twain_AcquireMulti2(ByVal sender As Object, ByVal e As TwainAcquireMultiPageEventArgs) 
   Dim msg As String 
 
   If e.FinishScan Then 
      msg = String.Format("The page # {0} is scanned and saved to file name {1}", e.PageNumber, e.FileName) 
      MessageBox.Show(msg) 
   End If 
 
   e.Cancel = False 
End Sub 
 
Public Sub AcquireFast2Example(ByVal parent As IntPtr) 
   Dim session As TwainSession = New TwainSession() 
   session.Startup(parent, "manufacturer", "productFamily", "version", "application", TwainStartupFlags.None) 
 
   session.EnableAcquireMultiPageEvent = True 
   AddHandler session.AcquireMultiPage, AddressOf twain_AcquireMulti2 
 
   ' 3, start page number to use when numbering output file names, output files should be test_0003.tif, test_0004.tif, ...etc 
   session.AcquireFast2(Path.Combine(LEAD_VARS.ImagesDir, "test.tif"), 
                        3, 
                        TwainFastUserInterfaceFlags.Show, TwainTransferMode.Buffer, RasterImageFormat.Tif, 1, True, 0, True) 
   session.Shutdown() 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 

Requirements

Target Platforms

Help Version 20.0.2020.3.31
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Twain Assembly