Set/Get a Twain Capability (C++ Builder 6.0)

Take the following steps to start a project and to add some code to use the Get/Set capability methods and then acquire your image using the newly set capability:

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. 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. Press install, and then compile and install the package dclusr.bpk.

4.

From the ActiveX controls tab, Add a LEAD Raster Twain control, and 3 LEAD Twain Capability controls to your form.

5.

If you didn’t import LEAD Raster Variant before, import it as follows:

6.

On the Project pull-down menu, use the Import Type library… and select the LEAD Raster Variant Object Library. Press install, and then compile and install the package dclusr.bpk.

7.

At the top of your form, add 3 button controls and name them as follows:

 

Name

Caption

 

btnSelectSource

Select Source

 

btnUseCapability

Use Capability

 

btnSetBrightness

Set Brightness

 

btnAcquire

Acquire

8.

Declare the following variable in the public section of "Unit1.h":

int nRet;

9.

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") ) ;
}

10.

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

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

11.

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 ( ) ;
}

12.

Handle the btnUseCapability OnClick event, and code the btnUseCapabilityClick procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code.

void __fastcall TForm1::btnUseCapabilityClick(TObject *Sender)
{
    ILEADRasterVariant* pXfer= NULL; 

   LEADTwainCapability1->set_EnableMethodErrors( false ); 
   LEADTwainCapability1->CapInfo->ConType= L_TWON_ONEVALUE; 
   LEADTwainCapability1-> CapInfo->Capability = L_ICAP_XFERMECH; 

   nRet = LEADRasterTwain1->GetCapability2 ( LEADTwainCapability1->GetDefaultInterface(), L_LTWAIN_CAPABILITY_GETCURRENT ); 
   if ( nRet == 0 ) 
   {
      pXfer = LEADTwainCapability1->CapOneValue->get_OneValCapValue();
      if ( pXfer->LongValue != L_TWSX_FILE ) 
      {
         LEADTwainCapability2->set_EnableMethodErrors ( false ); 
         LEADTwainCapability2-> CapInfo->Capability = L_ICAP_XFERMECH; 
         LEADTwainCapability2->CapInfo->ConType = L_TWON_ONEVALUE; 

         LEADTwainCapability2->CapOneValue->OneValItemType = L_TWTY_UINT16; 
         LEADTwainCapability2->CapOneValue->set_OneValCapValue (pXfer); 

         nRet = LEADRasterTwain1->SetCapability2( LEADTwainCapability2->GetDefaultInterface(), L_LTWAIN_CAPABILITY_SET ); 
      }
      else
         ShowMessage ( "The Transfer mode is File" ); 
   }
   else

      ShowMessage ( "Error occurred in the GetCapability method" );
}

13.

Handle the btnSetBrightness OnClick event, and code the btnSetBrightnessClick procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code.

void __fastcall TForm1::btnSetBrightnessClick(TObject *Sender)
{
   int iRet; 
   ILEADRasterVariant* pCapVal; 

   LEADTwainCapability3->CapInfo->ConType = L_TWON_ONEVALUE; 
   LEADTwainCapability3-> CapInfo->Capability = L_ICAP_BRIGHTNESS; 
   LEADTwainCapability3->set_EnableMethodErrors ( false ); 
CoCreateInstance(CLSID_LEADRasterVariant, 
    NULL, 
    CLSCTX_ALL, 
    IID_ILEADRasterVariant, 
    (void**)&pCapVal ); 
   pCapVal->set_Type ( VALUE_USHORT ); 
   pCapVal->set_LongValue ( 50 ); 

   LEADTwainCapability3->CapOneValue->OneValItemType = L_TWTY_FIX32; 
   LEADTwainCapability3->CapOneValue->set_OneValCapValue ( pCapVal ); 

   iRet= LEADRasterTwain1->SetCapability2(LEADTwainCapability3->GetDefaultInterface(), L_LTWAIN_CAPABILITY_SET); 
   if (iRet != 0) 
      ShowMessage ( "Error Setting Capability" ); 
if (pCapVal) 
 pCapVal->Release();
}

14.

Handle the btnAcquire 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)
{
   LEADRasterTwain1->set_FileTransferName ( AnsiToOLESTR("c:\\twain.bmp") );
   nRet= LEADRasterTwain1->Acquire ( L_LTWAIN_SHOW_USER_INTERFACE );
   if ( nRet != 0 )
     ShowMessage ( "Error acquiring from source" ) ;
}

15.

Include the following file in the Unit1.h" file.

#include "LTRASTERLib_TLB.h"

 

16.

Save your project and run your program to test it.