Set/Get a Twain Capability (Delphi 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 Delphi 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.dpk. |
|
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.dpk. |
|
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 (14.5). Press install, and then compile and install the package dclusr.dpk. |
|
7. |
At the top of your form, add 4 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: |
nRet: Integer;
9. |
Handle the Form1 OnCreate event, and code the FormCreate procedure as follows: |
procedure TForm1.FormCreate(Sender: TObject);
begin
LEADRasterTwain1.InitSession ( Handle ) ;
LEADRasterTwain1.EnableMethodErrors:= False;
{ Unlock Document support.
Note that this is a sample key, which will not work in your toolkit. }
LEADRasterTwain1.UnlockSupport ( L_SUPPORT_DOCUMENT, 'TestKey' ) ;
end;
10. |
Handle the Form1 OnClose event, and code the FormClose procedure as follows: |
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
LEADRasterTwain1.EndSession ( ) ;
end;
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. |
procedure TForm1.btnSelectSourceClick(Sender: TObject);
begin
LEADRasterTwain1.SelectSource ( ) ;
end;
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. |
procedure TForm1.btnUseCapabilityClick(Sender: TObject);
var
Xfer: LEADRasterVariant;
begin
LEADTwainCapability1.EnableMethodErrors:= False;
LEADTwainCapability1.CapInfo.ConType:= L_TWON_ONEVALUE;
LEADTwainCapability1.CapInfo.Capability:= L_ICAP_XFERMECH;
nRet:= LEADRasterTwain1.GetCapability2( LEADTwainCapability1.DefaultInterface, L_LTWAIN_CAPABILITY_GETCURRENT ) ;
if ( nRet = 0 ) then
begin
Xfer:= LEADTwainCapability1.CapOneValue.OneValCapValue;
if ( Xfer.LongValue <> L_TWSX_FILE ) then
begin
LEADTwainCapability2.EnableMethodErrors:= False;
LEADTwainCapability2.CapInfo.Capability:= L_ICAP_XFERMECH;
LEADTwainCapability2.CapInfo.ConType:= L_TWON_ONEVALUE;
LEADTwainCapability2.CapOneValue.OneValItemType:= L_TWTY_UINT16;
LEADTwainCapability2.CapOneValue.OneValCapValue:= Xfer;
nRet:= LEADRasterTwain1.SetCapability2 ( LEADTwainCapability2.DefaultInterface, L_LTWAIN_CAPABILITY_SET );
end
else
ShowMessage ( 'The Transfer mode is File' ) ;
end
else
ShowMessage ( 'Error occurred in GetCapability method' ) ;
end;
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. |
procedure TForm1.btnSetBrightnessClick(Sender: TObject);
var
iRet: Integer;
CapVal: LEADRasterVariant;
begin
LEADTwainCapability3.CapInfo.ConType:= L_TWON_ONEVALUE;
LEADTwainCapability3.CapInfo.Capability:= L_ICAP_BRIGHTNESS;
LEADTwainCapability3.EnableMethodErrors:= False;
CapVal:= coLEADRasterVariant.Create ( );
CapVal.Type_:= VALUE_USHORT;
CapVal.LongValue:= 50;
LEADTwainCapability3.CapOneValue.OneValItemType:= L_TWTY_FIX32;
LEADTwainCapability3.CapOneValue.OneValCapValue:= CapVal;
iRet:= LEADRasterTwain1.SetCapability2 (LEADTwainCapability3.DefaultInterface, L_LTWAIN_CAPABILITY_SET);
if (iRet <> 0) then
ShowMessage ( 'Error Setting Capability' ) ;
end;
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. |
procedure TForm1.btnAcquireClick(Sender: TObject);
begin
LEADRasterTwain1.FileTransferName:= 'c:\twain.bmp';
nRet:= LEADRasterTwain1.Acquire ( L_LTWAIN_SHOW_USER_INTERFACE ) ;
if ( nRet <> 0 ) then
ShowMessage ( 'Error acquiring from source' ) ;
end;
15. |
Add ‘LTRASTERLib_TLB’, and ‘LTRASTERVARIANTLib_TLB’ units to the uses section of Unit1. |
16. |
Save your project and run your program to test it. |