Available in the LEADTOOLS Imaging toolkit. |
Using the Fast TWAIN Feature (C++ Builder)
Take the following steps to start a project and to add some code that acquires images using Fast Twain:
1. |
Start C++ Builder 4.0. |
2. |
On the Project pull-down menu, use Import Type library… and select the LEAD RasterTwain Object Library. Press OK. |
3. |
On the Project pull-down menu, use Import Type library… and select the LEAD Raster Object Library . Press OK. |
4. |
On the Project pull-down menu, use Import Type library… and select the LEAD RasterIO Object Library . Press OK. |
5. |
Add the following code to the private section of Unit1.h: |
LEADTwainCapability* pTwainCap;
LEADRasterTwain* pRasterTwain;
int nRet;
6. |
Handle the Form1 OnCreate event, and code the FormCreate procedure as follows: |
void __fastcall TForm1::FormCreate(TObject *Sender)
{
CoCreateInstance (CLSID_LEADRasterTwainCapability, NULL, CLSCTX_ALL, IID_ICapability, (void **)&pTwainCap);
CoCreateInstance(CLSID_LEADRasterTwain, NULL, CLSCTX_ALL, IID_ILEADRasterTwain, (void**)&pRasterTwain);
pRasterTwain->UnlockSupport ( L_SUPPORT_DOCUMENT, AnsiToOLESTR ( "TestKey" ) ) ;
pRasterTwain->InitSession ( (long)Handle ) ;
pRasterTwain->EnableMethodErrors = False;
rbMemory->Checked= True;
}
7. |
Handle the Form1 OnClose event, and code the FormClose procedure as follows: |
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
pRasterTwain->EndSession ( ) ;
if ( pTwainCap )
pTwainCap->Release ( ) ;
if ( pRasterTwain )
pRasterTwain->Release ( ) ;
}
8. |
At the top of Form1, add check box and name it as follows: |
|
|
Name |
Caption |
|
chkUseBufferSize |
Use Buffer Size |
9. |
Add 2 radio buttons, and name them as follows: |
|
|
Name |
Caption |
|
rbNative |
Native Mode |
|
rbMemory |
Memory Mode |
10. |
Add 1 button, and name it as follows: |
|
|
Name |
Caption |
|
btnAcquire |
Fast Acquire |
11. |
Add 2 Edit boxes, and name them as follows: |
edtBufferSize
edtFName
12. |
Handle the btnAcquire control's OnClick event, and code the btnAcquireClick procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code. |
void __fastcall TForm1::btnAcquireClick(TObject *Sender)
{
if ( rbMemory->Checked )
{
pRasterTwain->FastTransferMode = L_LTWAIN_BUFFER_MODE ;
pRasterTwain->FastFormat = FILE_CCITT_GROUP4 ;
}
else
{
pRasterTwain->FastTransferMode = L_LTWAIN_NATIVE_MODE ;
pRasterTwain->FastFormat = FILE_TIF;
}
pRasterTwain->FastBitsPerPixel = 1;
pRasterTwain->FastUsePreferredBufferSize = chkUseBufferSize->Checked;
if ( pRasterTwain->FastUsePreferredBufferSize )
pRasterTwain->FastBufferSize = StrToInt(edtBufferSize->Text);
nRet= pRasterTwain->AcquireMulti ( AnsiToOLESTR ( edtFName->Text.c_str() ), (long)(L_LTWAIN_SHOW_USER_INTERFACE | L_LTWAIN_USE_THREAD_MODE), (TOLEBOOL)true );
if ( nRet == 0 )
ShowMessage ( "Fast Scanning process done successfully..." ) ;
else
ShowMessage ( "AcquireMulti failed, Error = " + IntToStr ( nRet ) ) ;
}
13. |
In the Unit1.h file include these files. |
#include "LTRASTERTWAINLib_TLB.h"
#include "LTRASTERLib_TLB.h"
#include "LTRASTERIOLib_TLB.h"
14. |
Save your project and run your program to test it. |