Get a Fast Twain Scan from a Scanner (C++ Builder 6.0)
Take the following steps to start a project and to add some code to find the fastest configuration for your scanner using the LEADTOOLS Fast TWAIN feature:
1. |
Start C++ Builder 6.0. |
|
2. |
If you didn’t import LEAD Raster before, import it as follows: |
|
|
On the Project pull-down menu, use Import Type library… and select the LEAD Raster Object Library (14.5). Press install, and then compile and install the package dclusr.bpk. |
|
3. |
If you didn’t import LEAD Raster Twain before, import it as follows: |
|
|
On the Project pull-down menu, use Import Type library… and select the LEAD RasterTwain Object Library (14.5). Press install, and then compile and install the package dclusr.bpk. |
|
4. |
From the ActiveX controls tab, add the LEAD Raster Twain control to your form. |
|
5. |
At the top of your form, add 3 button controls and name them as follows: |
|
|
Name |
Caption |
|
btnSelectSource |
Select Source |
|
btnFindFastConfig |
Find Fast Config. |
|
btnAcquireFastConfig |
Acquire Fast Config. |
6. |
Declare the following variable in the public section of "Unit1.h". |
int nRet;
7. |
Handle the Form1 OnCreate event, and code the FormCreate procedure as follows: |
void __fastcall TForm1::FormCreate(TObject *Sender)
{
LEADRasterTwain1->InitSession ( (long)Handle ) ;
LEADRasterTwain1->set_EnableMethodErrors ( false );
/* Unlock Document support.
Note that this is a sample key, which will not work in your toolkit. */
LEADRasterTwain1->UnlockSupport ( L_SUPPORT_DOCUMENT, AnsiToOLESTR("TestKey") ) ;
}
8. |
Handle the Form1 OnClose event, and code the FormClose procedure as follows: |
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
LEADRasterTwain1->EndSession ( ) ;
}
9. |
Handle the btnSelectSource OnClick event, and code the btnSelectSourceClick procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code. |
void __fastcall TForm1::btnSelectSourceClick(TObject *Sender)
{
LEADRasterTwain1->SelectSource ( ) ;
}
10. |
Handle the btnFindFastConfig OnClick event, and code the btnFindFastConfigClick procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code. |
void __fastcall TForm1::btnFindFastConfigClick(TObject *Sender)
{
LEADRasterTwain1->set_UserFastConfigsCount ( 0 );
LEADRasterTwain1->set_EnableFastConfigEvent ( false );
nRet= LEADRasterTwain1->FindFastConfig ( AnsiToOLESTR("c:\\temp"), L_LTWAIN_SHOW_USER_INTERFACE | L_LTWAIN_USE_THREAD_MODE, 8, 5);
if ( nRet == 0 )
ShowMessage ( "Find Fast Configuration process completed " );
else
ShowMessage ( "An error occurred during the Finding Fast Configuration process." ) ;
}
11. |
Handle the btnAcquireFastConfig OnClick event, and code the btnAcquireFastConfigClick procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code. |
void __fastcall TForm1::btnAcquireFastConfigClick(TObject *Sender)
{
LEADRasterTwain1->set_FastTransferMode (LEADRasterTwain1->BestFastConfig->TransferMode ) ;
LEADRasterTwain1->set_FastFormat (LEADRasterTwain1->BestFastConfig->FileFormat );
LEADRasterTwain1->set_FastBitsPerPixel (LEADRasterTwain1->BestFastConfig->BitsPerPixel );
LEADRasterTwain1->set_FastBufferSize (LEADRasterTwain1->BestFastConfig->BufferSize );
LEADRasterTwain1->set_FastUsePreferredBufferSize ( true );
LEADRasterTwain1->set_EnableAcquireMultiEvent ( false) ;
nRet = LEADRasterTwain1->AcquireMulti ( AnsiToOLESTR("c:\\temp\\test"), L_LTWAIN_SHOW_USER_INTERFACE, true);
if ( nRet == 0 )
ShowMessage ( "Image acquisition using the Fast TWAIN Configuration is completed" );
else
ShowMessage ( "An error occurred while acquiring an image using the Fast TWAIN Configuration." ) ;
}
11. |
Include the following file in Unit1.h" file. |
#include "LTRASTERLib_TLB.h"
12. |
Save your project and run your program to test it. |