Get a Fast Twain Scan from a Scanner (C++ Builder)

Get a Fast Twain Scan from a Scanner (C++ Builder)

Take the following steps to get fast twain scan using the LEADTOOLS Fast TWAIN features:

1.

Start C++ Builder.

2.

In the File menu, choose New Application.

3.

On the Delphi toolbar, click the LEADTOOLS tab. If you have used a LEAD VCL control before, the icon appears on the toolbar. Otherwise, refer to Installing VCL before continuing with this tutorial.

4.

Select and Add the LEAD TWAIN control from the VCL toolbar to your Main Form.

5.

image\btndbtn.gif Add 3 buttons to your form and name them as follows:

 

Name

Caption

 

btnSelectSource

Select Source

 

btnFindFastConfig

Find Fast Config

 

btnAcquireFastConfig

Acquire Fast Config

6.

Define the following variable in the private section of Form1:

 

FASTCONFIG BestConfig;

7.

Handle the Form1 OnCreate event, and code the FormCreate method as follows:

void __fastcall TForm1::FormCreate(TObject *Sender) 
{
   L_INT nRet; 
 LEADTwain1->EnableMethodErrors = false; 
 LEADTwain1->ManName = "LEAD Technologies, Inc."; 
   LEADTwain1->ProdFamily = "LEAD Test Applications";
   LEADTwain1->Version = "Version 1.0";
   LEADTwain1->AppName = "TWAIN Test Application";
   nRet= LEADTwain1->InitSession ( (L_HANDLE)Handle ); 
 if ( nRet != SUCCESS ) 
   {
      ShowMessage ( "Failure to Initialize TWAIN" ); 
      return; 
   }
   LEADTwain1->EnableMethodErrors = True; 
   /* Unlock Document support. 
       Note that this is a sample key, which will not work in your toolkit. */
   LEADTwain1->UnlockSupport ( L_SUPPORT_DOCUMENT, "TestKey" ); 
}

8.

Handle the Form1 OnClose event, and code the FormClose method as follows:

void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action) 
{
 LEADTwain1->EndSession ( ); 
}

9.

Handle the btnSelectSource OnClick event, and code the btnSelectSourceClick method as follows:

void __fastcall TForm1::btnSelectSourceClick(TObject *Sender)

{

 LEADTwain1->SelectSource ( );

}

 

10.

Handle the btnFindFastConfig OnClick event, and code the btnFindFastConfigClick method as follows:

void __fastcall TForm1::btnFindFastConfigClick(TObject *Sender) 
{
 L_INT nRet; 
 L_INT nTestConfigsCount= 0; 
  pFASTCONFIG pTestConfigs= NULL; 

 LEADTwain1->EnableMethodErrors = false; 
 nRet= LEADTwain1->FindFastConfig ( "c:\temp",
LTWAIN_SHOW_USER_INTERFACE | LTWAIN_USE_THREAD_MODE, 
8, 
                                      5, 
                                      NULL, 
                                      0, 
                                      &pTestConfigs, 
                                      &nTestConfigsCount, 
                                      &BestConfig ); 

 if ( nRet == SUCCESS ) 
    ShowMessage ( "Find Fast Configuration process completed" ); 
   else
    ShowMessage ( "An error occurred during the Finding Fast Configuration process." ); 

   LEADTwain1->EnableMethodErrors = True; 
}

11.

Handle the btnAcquireFastConfig OnClick event, and code the btnAcquireFastConfigClick method as follows:

void __fastcall TForm1::btnAcquireFastConfigClick(TObject *Sender) 
{
 L_INT nRet; 

 LEADTwain1->EnableMethodErrors = False; 
   nRet= LEADTwain1->AcquireMulti ( "c:\\temp\\testconfig.tif",
 LTWAIN_SHOW_USER_INTERFACE | LTWAIN_USE_THREAD_MODE, 
                                    BestConfig.uTransferMode, 
                                BestConfig.nFileFormat, 
                                BestConfig.nBitsPerPixel, 
                                true, 
                                BestConfig.ulBufferSize, 
                                true ); 
 if ( nRet == SUCCESS ) 
    MessageBox ( Handle, "Image acquisition using the Fast TWAIN Configuration is completed.", "Fast Config", MB_OK ); 
   else
    MessageBox ( Handle, "An error occurred while acquiring images using the Fast TWAIN Configuration.", "Fast Config", MB_OK ); 

 LEADTwain1->EnableMethodErrors = true; 
}

12.

Run your program to test it.