Using the Fast TWAIN Feature (C++ Builder)

Take the following steps to start a project and to add some code that acquires the images using Fast Twain:

1.

Start C++ Builder.

2.

On the C++ Builder 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.

3.

Select the LEAD Twain control on the LEADTOOLS toolbar. Place the control anywhere on the form.

4.

At the top of your form, add a check box and name it as follows:

 

Name

Caption

 

chkUseBufferSize

Use Buffer Size

5.

Add 2 radio buttons to your form, and name them as follows:

 

Name

Caption

 

rbNative

Native Mode

 

rbMemory

Memory Mode

6.

Add 1 button to your form, and name it as follows:

 

Name

Caption

 

btnAcquire

Fast Acquire

7.

Add 2 Edit boxes to your form, and name them as follows:

 

Name

 

 

edtFName

 

 

edtBufferSize

 

8.

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

void __fastcall TForm1::FormCreate(TObject *Sender) 
{
 LEADTwain1->UnlockSupport ( L_SUPPORT_DOCUMENT, "TestKey" ); 
   LEADTwain1->InitSession ( (L_HANDLE)Handle ) ; 
   LEADTwain1->EnableMethodErrors = false; 
   rbMemory->Checked= true; 
}

9.

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

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

10.

Handle the btnAcquire control's OnClick event, and code the btnAcquireClick procedure as follows.

void __fastcall TForm1::btnAcquireClick(TObject *Sender) 
{
 L_INT nRet; 
 L_INT nFormat; 
   L_UINT uTransferMode; 
   bool bMemory; 

   bMemory= rbMemory->Checked; 
   if ( bMemory ) 
   {
      uTransferMode= LTWAIN_BUFFER_MODE; 
      nFormat= FILE_CCITT_GROUP4; 
   }
   else
   {
      uTransferMode= LTWAIN_NATIVE_MODE; 
      nFormat= FILE_TIF; 
   }

   nRet= LEADTwain1->AcquireMulti ( edtFName->Text, 
                                    LTWAIN_SHOW_USER_INTERFACE | LTWAIN_USE_THREAD_MODE, 
                                    uTransferMode, 
                                    nFormat, 
                                    1, 
                                    true, 
                                    StrToInt(edtBufferSize->Text), 
                                    !chkUseBufferSize->Checked ); 

   if ( nRet == SUCCESS ) 
      ShowMessage ( "Fast Scanning process done successfully..." ); 
   else
   {
      ShowMessage ( "AcquireMulti failed, Error = " + IntToStr(nRet) ); 
   }
}

11.

Run your program to test it.