Take the following steps to get fast TWAIN scan using the LEADTOOLS Fast TWAIN features:
TwainTutor2
.Examples\Scanning\ClassLibrary
directory of your LEAD installation. For example, if you installed LEADTOOLS in C:\LEADTOOLS22\
, enter C:\LEADTOOLS22\Examples\Scanning\ClassLibrary
, then Click OK. Then click Next.Add the following line immediately before the class CTwainTutor2App
declaration (keep in mind, you may have to change the path to where the header files reside):
#include "..\..\..\..\include\ClassLib\ltwrappr.h"
Click the Class View tab.
CTwainTutor2App(void)
constructor.Add the following lines after //TODO: add construction code here
:
LBase::LoadLibraries(LT_ALL_LEADLIB);
L_TCHAR * pszLicenseFile = L"Replace this with the path to the LEADTOOLS license file";
L_TCHAR * pszDeveloperKey = L"Replace this with your developer key";
LSettings::SetLicenseFile(pszLicenseFile, pszDeveloperKey);
Create a new file called Imports.cpp and place it beside your project files.
TwainTutor2
folder to open it.Source
files folder and select Add New item.Imports.cpp
.imports.cpp
in the Solution Explorer and add the following lines:
#include "StdAfx.h"
#if defined(WIN64)
#else
#pragma comment(lib, "..\\..\\..\\..\\Lib\\CDLL\\Win32\\Ltwvc_u.lib")
#endif // #if defined(WIN64)
Click the Solution Explorer tab.
Add the following class declaration before the CTwainTutor2Dlg
class.
class LMyTwain : public LTwain
{
LEAD_DECLAREOBJECT(LMyTwain);
public:
LMyTwain();
virtual ~LMyTwain();
virtual L_INT BitmapCallBack(pBITMAPHANDLE pBitmap);
};
Click the Solution Explorer tab.
Add the following class:
LEAD_IMPLEMENTOBJECT(LMyTwain);
LMyTwain::LMyTwain()
{
EnableCallBack(TRUE);
}
LMyTwain::~LMyTwain()
{
}
L_INT LMyTwain::BitmapCallBack(pBITMAPHANDLE pBitmap)
{
//Copy the acquired bitmap here
return SUCCESS;
}
Click the Class View tab.
LMyTwain
, and for Variable Declaration put m_MyTwain
. Leave Access as Public
and click OK.CTwainTutor2Dlg
branch. Double-click the OnInitDialog()
function and add the following code after line://TODO: Add extra initialization here
APPLICATIONDATA AppData;
memset(&AppData, 0, sizeof(APPLICATIONDATA));
AppData.hWnd = m_hWnd;
AppData.uStructSize = sizeof(AppData);
lstrcpy(AppData.szManufacturerName, _T("LEAD Technologies, Inc."));
lstrcpy(AppData.szAppProductFamily, _T("LEAD Test Applications"));
lstrcpy(AppData.szVersionInfo, _T("Version 1.0"));
lstrcpy(AppData.szAppName, _T("TWAIN Test Application"));
m_MyTwain.InitSession(&AppData);
CTwainTutor2Dlg branch
, and choose Properties.Messages
icon. Then click the empty area beside the item WM_DESTROY
and choose OnDestroy
.Add the following code after the opening bracket {
:
m_MyTwain.EndSession();
LBase::UnloadLibraries(LT_ALL_LEADLIB);
Click the *Class View tab.
CTwainTutor2Dlg
and select Add "Add Variable...".FASTCONFIG
, and for Variable Declaration put m_BestConfig
. Leave Access as Public
and click OK.IDD_TWAINTUTOR2_DIALOG
.Now, drag and drop 3 buttons, and change their properties as follows:
Control | ID | Caption |
---|---|---|
Button1 | IDC_SELECT_SOURCE | Select Source |
Button2 | IDC_FIND_FAST_CONFIG | Find Fast Config |
Button3 | IDC_ACQUIRE_FAST_CONFIG | Acquire Fast Config |
From the View menu, select the Other Windows menu, then select the Resource View menu, then select the Dialog, and select IDD_TWAINTUTOR2_DIALOG
.
Double-click the Select Source button, and add the following code:
m_MyTwain.SelectSource(NULL);
From the View menu, select the Other Windows menu, then select the Resource View menu, then select the Dialog, and select IDD_TWAINTUTOR2_DIALOG
.
Double-click the Find Fast Config button, and add the following code:
pFASTCONFIG pTestConfigs = NULL;
L_INT nTestConfigsCount = 0;
L_INT nRet;
nRet = m_MyTwain.FindFastConfig(TEXT("c:\\temp"),
LTWAIN_SHOW_USER_INTERFACE | LTWAIN_USE_THREAD_MODE,
8, 5, NULL, 0,
&pTestConfigs,
&nTestConfigsCount,
&m_BestConfig,
sizeof(FASTCONFIG));
if (nRet == SUCCESS)
AfxMessageBox(TEXT("Find Fast Configuration process completed"));
else
AfxMessageBox(TEXT("An error occurred during the Finding Fast Configuration process."));
From the View menu, select the Other Windows menu, then select the Resource View menu, then select Dialog, and select IDD_TWAINTUTOR2_DIALOG
Double-click the Acquire Fast Config button, and add the following code:
L_INT nRet;
nRet = m_MyTwain.FastAcquire(TEXT("c:\\temp\\testconfig.tif"),
LTWAIN_SHOW_USER_INTERFACE | LTWAIN_USE_THREAD_MODE,
m_BestConfig.uTransferMode,
m_BestConfig.nFileFormat,
m_BestConfig.nBitsPerPixel,
TRUE,
m_BestConfig.ulBufferSize,
TRUE);
if (nRet == SUCCESS)
AfxMessageBox(TEXT("Image acquisition using the Fast TWAIN Configuration is completed."));
else
AfxMessageBox(TEXT("An error occurred while acquiring images using the Fast TWAIN Configuration."));
Compile and test the program.