Available in the LEADTOOLS Imaging toolkit. |
Acquiring an Image (C++ Builder 6.0)
Take the following steps to start a project and to add some code that acquires an image from a TWAIN source:
1. |
Start C++ Builder 6.0. |
|
2. |
If you didn’t install LEAD RasterView Control, install it as follows: |
|
|
On the Component pull-down menu, use Import ActiveX Control… and select the LEAD RasterView Control. Press install, and then compile and install the package dclusr.bpk. |
|
3. |
Select the LEAD RasterView control and add it to your form. Size and position the control, as you want it to appear at run time. |
|
4. |
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. |
|
5. |
From the ActiveX controls tab, add the LEAD Raster Twain and LEAD Twain Capability to your form. |
|
6. |
If you didn’t import LEAD Raster Variant before, import it as follows: |
|
7. |
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. |
|
8. |
From the ActiveX controls tab, add the LEAD Raster Variant control to your form. |
|
9. |
At the top of your form, add 9 Buttons and name them as follows: |
|
|
Name |
Caption |
|
btnOK |
OK |
|
btnCancel |
Cancel |
|
btnAcquire |
Acquire |
|
btnSelectSource |
Select Source |
|
btnSaveTemplate |
Save Template File |
|
btnLoadTemplate |
Load Template File |
|
btnNative |
Native |
|
btnMemBuf |
Memory Buffered |
|
btnFile |
File |
10. |
Add the following code to the private section of "Unit1.h". |
int nXferMode;
int nRet;
int TwainSetCapability ( short iCapability,
ILEADRasterVariant* pCapVal,
short iItemType );
11. |
Handle the Form1 OnCreate event, and code the FormCreate procedure as follows: |
void __fastcall TForm1::FormCreate(TObject *Sender)
{
LEADRasterTwain1->InitSession ( (long)Handle ) ;
}
12. |
Handle the Form1 OnClose event, and code the FormClose procedure as follows: |
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
LEADRasterTwain1->EndSession ();
}
13. |
Handle the btnOK OnClick event, and code the btnOKClick procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code. |
void __fastcall TForm1::btnOKClick(TObject *Sender)
{
Close ( ) ;
}
14. |
Handle the btnCancel OnClick event, and code the btnCancelClick procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code: |
void __fastcall TForm1::btnCancelClick(TObject *Sender)
{
Close ( ) ;
}
15. |
Handle the btnAcquire OnClick event, and code the btnAcquireClick procedure as follows: |
void __fastcall TForm1::btnAcquireClick(TObject *Sender)
{
LEADRasterTwain1->Acquire ( L_LTWAIN_SHOW_USER_INTERFACE ) ;
}
16. |
Handle the btnSelectSource OnClick event, and code the btnSelectSourceClick procedure as follows: |
void __fastcall TForm1::btnSelectSourceClick(TObject *Sender)
{
LEADRasterTwain1->SelectSource ( ) ;
}
17. |
Handle the btnSaveTemplate OnClick event, and code the btnSaveTemplateClick procedure as follows: |
void __fastcall TForm1::btnSaveTemplateClick(TObject *Sender)
{
nRet= LEADRasterTwain1->SaveTemplate ( AnsiToOLESTR("c:\\test.ltt") );
}
18. |
Handle the btnLoadTemplate OnClick event, and code the btnLoadTemplateClick procedure as follows: |
void __fastcall TForm1::btnLoadTemplateClick(TObject *Sender)
{
nRet= LEADRasterTwain1->LoadTemplate ( AnsiToOLESTR("c:\\test.ltt") ) ;
}
19. |
Handle the btnNative button’s OnClick event, and code the btnNativeClick procedure as Follows: |
void __fastcall TForm1::btnNativeClick(TObject *Sender)
{
nXferMode= L_TWSX_NATIVE;
LEADRasterVariant1->set_Type ( VALUE_USHORT );
LEADRasterVariant1->set_LongValue ( nXferMode );
TwainSetCapability ( L_ICAP_XFERMECH,
LEADRasterVariant1->GetDefaultInterface(),
L_TWTY_UINT16 );
}
20. |
Handle the btnMemBuf button’s OnClick event, and code the btnMemBufClick procedure as follows: |
void __fastcall TForm1::btnMemBufClick(TObject *Sender)
{
nXferMode= L_TWSX_MEMORY;
LEADRasterVariant1->set_Type ( VALUE_USHORT );
LEADRasterVariant1->set_LongValue ( nXferMode );
TwainSetCapability ( L_ICAP_XFERMECH,
LEADRasterVariant1->GetDefaultInterface( ),
L_TWTY_UINT16 );
}
21. |
Handle the btnFile OnClick event, and code the btnFileClick procedure as follows: |
void __fastcall TForm1::btnFileClick(TObject *Sender)
{
nXferMode= L_TWSX_FILE;
LEADRasterVariant1->set_Type ( VALUE_USHORT );
LEADRasterVariant1->set_LongValue ( nXferMode );
TwainSetCapability ( L_ICAP_XFERMECH, LEADRasterVariant1->GetDefaultInterface ( ), L_TWTY_UINT16 ) ;
LEADRasterTwain1->set_FileTransferName( AnsiToOLESTR ("c:\\twain.bmp") );
}
22. |
Handle the LEADRasterTwain1 OnAcquirePageEvent event, and code the LEADRasterTwain1AcquirePageEvent procedure as follows: |
void __fastcall TForm1::LEADRasterTwain1AcquirePageEvent(TObject *Sender,
long pBitmap)
{
ShowMessage ( "Acquisition of Image Done" ) ;
LEADRasterView1->Raster->InsertBitmapListItem ( -1, pBitmap ) ;
}
23. |
Add the TwainSetCapability function body to the Unit1 file. |
int TForm1::TwainSetCapability ( short iCapability, ILEADRasterVariant* pCapVal, short iItemType )
{
int iRet;
LEADTwainCapability1->set_EnableMethodErrors( false );
LEADTwainCapability1->CapInfo->Capability= iCapability;
LEADTwainCapability1->CapInfo->ConType= L_TWON_ONEVALUE;
LEADTwainCapability1->CapOneValue->OneValItemType= iItemType;
LEADTwainCapability1->CapOneValue->set_OneValCapValue( pCapVal );
iRet= LEADRasterTwain1->SetCapability2( LEADTwainCapability1->GetDefaultInterface(),
L_LTWAIN_CAPABILITY_SET);
return iRet;
}
24. |
Run your program to test it. |