L_TwainAcquireMulti2

#include "lttwn.h"

L_LTTWN_API L_INT L_TwainAcquireMulti2(hSession, pszBaseFileName, nStartPageNumber, uFlags, uTransferMode, nFormat, nBitsPerPixel, bMultiPageFile, uUserBufSize, bUsePreferredBuffer, pfnCallBack, pUserData)

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

Parameters

HTWAINSESSION hSession

Handle to an existing TWAIN session. This handle is obtained by calling the L_TwainInitSession or L_TwainInitSession2 function.

L_TCHAR *pszBaseFileName

Character string containing the base name of the image file(s) in which to save the acquired data.

L_INT nStartPageNumber

The starting page number where the numerical sequence of the newly scanned file names starts.

If the file format specified in nFormat does not support multipage files, the value of bMultiPageFile will be ignored and the function will automatically save the acquired images in separate files.

The naming of the files will be carried out as follows:

If the file format supports multipage files, this function will use the bMultiPageFile parameter to determine how to save multiple images.

- If bMultiPageFile is FALSE, each scanned page will be saved to a separate file, named in the same manner described in the paragraph above.

Pass -1 for this parameter to start numbering files from page 1, which in this case the first scanned file will have the format "Temp0001.bmp".

L_UINT uFlags

Flag that determines certain actions of the TWAIN source. Possible values are:

Value Meaning
LTWAIN_SHOW_USER_INTERFACE [0x0001] Show the manufacturer's user interface as modeless.
LTWAIN_MODAL_USER_INTERFACE [0x0002] Show the manufacturer's user interface as a modal dialog. Works only if the LTWAIN_SHOW_USER_INTERFACE flag is set.
LTWAIN_KEEPOPEN [0x0020] Keep the TWAIN data source open after scanning.

L_UINT uTransferMode

Flag that indicates the transfer mode to use when acquiring the image(s). Possible values are:

Value Meaning
LTWAIN_FILE_MODE [0x001] Use the File transfer mode
LTWAIN_BUFFER_MODE [0x002] Use the Memory transfer mode
LTWAIN_NATIVE_MODE [0x004] Use the Native transfer mode

L_INT nFormat

Output file format. Valid values depend on the transfer mode used.

L_INT nBitsPerPixel

Resulting file's pixel depth. If nBitsPerPixel is 0, the file will be stored using the closest BitsPerPixel value supported by that format.

Note that not all bits per pixel are available to all file formats. For valid values, refer to Formats of Output Files.

L_BOOL bMultiPageFile

Flag that indicates whether to save multiple images into a single multipage file, or into a series of single page files. Possible values are:

Value Meaning
TRUE The scanned images will be saved in one multipage file.
FALSE Each scanned image will be saved in a separate file.

Note: If the format does not support multipage files, then each scanned page will be saved in a separate file.

L_UINT32 uUserBufSize

Specifies a user-defined buffer size. This value will be used if uTransferMode is LTWAIN_BUFFER_MODE and the bUsePreferredBuffer parameter is FALSE. This value must be a multiple of 16.

L_BOOL bUsePreferredBuffer

Flag that indicates whether to use the user-defined buffer size or the Twain driver preferred buffer size. Possible values are:

Value Meaning
TRUE Use the Twain driver preferred buffer size.
FALSE Use the user-defined buffer size in the uUserBufSize parameter.

LTWAINACQUIRECALLBACK pfnCallBack

Optional callback function, called twice for each page scan. The 1st call is to notify the page is start scanning, and the 2nd call is to notify the page scanning is finished.

L_VOID * pUserData

Void pointer that you can use to pass one or more additional parameters that the callback function needs. To use this feature, assign a value to a variable or create a structure that contains as many fields as you need. Then, in this parameter, pass the address of the variable or structure, casting it to L_VOID *. The callback function, which receives the address in its own pUserData parameter, can cast it to a pointer of the appropriate data type to access your variable or structure.

Returns

Value Meaning
SUCCESS The function was successful.
! = SUCCESS An error occurred. Refer to Return Codes.

Comments

This function will acquire one or more images from a TWAIN source and store the images to the specified file(s).

This function was added in order to allow users to prevent already scanned files from being overwritten by a subsequent scan batch. To do this, specify the page number where new file creation should start numbering files. If, for example, three pages are scanned while the specified pszBaseFileName parameter is "BaseFileName.bmp", then the output files will have the names, "BaseFileName0001.bmp", "BaseFileName0002.bmp" and "BaseFileName0003.bmp", etc. If you were to start a new scan with the nStartPageNumber remaining at -1, then the saved files will be overwritten. In order to avoid that, pass 4 for the nStartPageNumber parameter so the new scanned files will start from 4. The file will save as "BaseFileName_0004.bmp", "BaseFileName_0005.bmp", ...etc.

If the file format specified in nFormat does not support multipage files, the value of bMultiPageFile will be ignored and the function will automatically save the acquired images in separate files. The naming of the files will be carried out as follows:

If the file format specified in nFormat supports multipage files, this function will use the bMultiPageFile parameter to determine how to save multiple images.

If uTransferMode is LTWAIN_BUFFER_MODE, and bUsePreferredBuffer is FALSE, the function will use the user-defined buffer size in uUserBufSize.

If, however, bUsePreferredBuffer is TRUE, then the function will use the TWAIN driver preferred buffer size and ignore uUserBufSize.

To cancel the acquire operation, call the L_TwainCancelAcquire.

To stop acquiring images only from the feeder of the TWAIN source, call the L_TwainStopFeeder function.

The LTWAIN_KEEPOPEN flag works only in the following cases:

  1. Passed with LTWAIN_SHOW_USER_INTERFACE flag to make the TWAIN user-interface appear as a modeless dialog. The TWAIN data source remains open after scanning until the user closes it.

  2. Passed with LTWAIN_SHOW_USER_INTERFACE and LTWAIN_MODAL_USER_INTERFACE flags to make the TWAIN user-interface appear as a modal dialog. The TWAIN data source remains open after scanning until the user closes it.

Required DLLs and Libraries

See Also

Functions

Topics

Example

For complete sample, refer to FASTTWN
demo.

L_VOID EXT_CALLBACK AcquireMultiCB(HTWAINSESSION hSession, 
                                   L_INT         nPage, 
                                   L_TCHAR*      pszFileName, 
                                   L_BOOL        bFinishScan, 
                                   L_VOID*       pUserData) 
{ 
   UNREFERENCED_PARAMETER(hSession); 
   UNREFERENCED_PARAMETER(pUserData); 
 
   L_TCHAR szTemp[MAX_PATH]; 
   if (bFinishScan) 
   { 
      wsprintf(szTemp, TEXT("The page # %d is scanned and saved to file name %s\n"), nPage, pszFileName); 
      MessageBox(NULL, szTemp, TEXT("Notice"), MB_OK); 
   } 
} 
 
L_INT TwainAcquireMulti2Example(HWND hWnd,HTWAINSESSION hSession) 
{ 
   L_INT nRet; 
 
   nRet = L_TwainAcquireMulti2(hSession, 
                              MAKE_IMAGE_PATH(TEXT("test.tif")), 
                              3, // start page number to use when numbering output file names, output files should be test_0003.tif, test_0004.tif, ...etc 
                              LTWAIN_SHOW_USER_INTERFACE, 
                              LTWAIN_BUFFER_MODE, 
                              FILE_TIF, 
                              1, 
                              TRUE, 
                              0,  
                              FALSE, 
                              AcquireMultiCB, NULL); 
 
   if (nRet == SUCCESS) 
      MessageBox(hWnd, TEXT("Fast Twain function was successful"), TEXT("Notice"), MB_OK); 
   else 
      MessageBox(hWnd, TEXT("Error occurred during fast Twain function!!!"), TEXT("Error!!!"), MB_OK); 
 
   return nRet; 
} 

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

LEADTOOLS TWAIN C API Help