Acquiring an Image (Delphi 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 Delphi 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 (14.5). Press install, and then compile and install the package dclusr.dpk. |
|
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 (14.5). Press install, and then compile and install the package dclusr.dpk. |
|
5. |
From the ActiveX controls tab, add the LEAD Raster Twain control and the LEAD Twain Capability control 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 (14.5). Press install, and then compile and install the package dclusr.dpk. |
|
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: |
nXferMode: Integer;
nRet: Integer;
Function TwainSetCapability ( uCapability: Integer;
CapVal: LEADRasterVariant;
uItemType: Integer ): Integer;
11. |
Handle the Form1 OnCreate event, and code the FormCreate procedure as follows: |
procedure TForm1.FormCreate(Sender: TObject);
begin
LEADRasterTwain1.InitSession ( Handle ) ;
end;
12. |
Handle the Form1 OnClose event, and code the FormClose procedure as follows: |
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
LEADRasterTwain1.EndSession ();
end;
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. |
procedure TForm1.btnOKClick(Sender: TObject);
begin
Close ( ) ;
end;
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: |
procedure TForm1.btnCancelClick(Sender: TObject);
begin
Close ( ) ;
end;
15. |
Handle the btnAcquire OnClick event, and code the btnAcquireClick procedure as follows: |
procedure TForm1.btnAcquireClick(Sender: TObject);
begin
LEADRasterTwain1.Acquire ( L_LTWAIN_SHOW_USER_INTERFACE ) ;
end;
16. |
Handle the btnSelectSource OnClick event, and code the btnSelectSourceClick procedure as follows: |
procedure TForm1.btnSelectSourceClick(Sender: TObject);
begin
LEADRasterTwain1.SelectSource ( ) ;
end;
17. |
Handle the btnSaveTemplate OnClick event, and code the btnSaveTemplateClick procedure as follows: |
procedure TForm1.btnSaveTemplateClick(Sender: TObject);
begin
nRet:= LEADRasterTwain1.SaveTemplate ('c:\test.ltt');
end;
18. |
Handle the btnLoadTemplate OnClick event, and code the btnLoadTemplateClick procedure as follows: |
procedure TForm1.btnLoadTemplateClick(Sender: TObject);
begin
nRet:= LEADRasterTwain1.LoadTemplate ( 'c:\test.ltt' ) ;
end;
19. |
Handle the btnNative button’s OnClick event, and code the btnNativeClick procedure as Follows: |
procedure TForm1.btnNativeClick(Sender: TObject);
begin
nXferMode:= L_TWSX_NATIVE;
LEADRasterVariant1.Type_:= VALUE_USHORT;
LEADRasterVariant1.LongValue:= nXferMode;
TwainSetCapability ( L_ICAP_XFERMECH,
LEADRasterVariant1.DefaultInterface,
L_TWTY_UINT16 );
end;
20. |
Handle the btnMemBuf button’s OnClick event, and code the btnMemBufClick procedure as follows: |
procedure TForm1.btnMemBufClick(Sender: TObject);
begin
nXferMode:= L_TWSX_MEMORY;
LEADRasterVariant1.Type_:= VALUE_USHORT;
LEADRasterVariant1.LongValue:= nXferMode;
TwainSetCapability ( L_ICAP_XFERMECH, LEADRasterVariant1.DefaultInterface, L_TWTY_UINT16 );
end;
21. |
Handle the btnFile option OnClick event, and code the btnFileClick procedure as follows: |
procedure TForm1.btnFileClick(Sender: TObject);
begin
nXferMode:= L_TWSX_FILE;
LEADRasterVariant1.Type_:= VALUE_USHORT;
LEADRasterVariant1.LongValue:= nXferMode;
TwainSetCapability ( L_ICAP_XFERMECH, LEADRasterVariant1.DefaultInterface, L_TWTY_UINT16 );
LEADRasterTwain1.FileTransferName:= 'c:\twain.bmp';
end;
22. |
Handle the LEADRasterTwain1 OnAcquirePageEvent event, and code the LEADRasterTwain1AcquirePageEvent procedure as follows: |
procedure TForm1.LEADRasterTwain1AcquirePageEvent(Sender: TObject;
pBitmap: Integer);
begin
ShowMessage ( 'Acquisition of Image Done' ) ;
LEADRasterView1.Raster.InsertBitmapListItem ( -1, pBitmap ) ;
end;
23. |
Add the TwainSetCapability function body to the Unit1 file. |
Function TForm1.TwainSetCapability ( uCapability: Integer; CapVal: LEADRasterVariant; uItemType: Integer): Integer;
var
iRet: Integer;
begin
LEADTwainCapability1.EnableMethodErrors:= False;
LEADTwainCapability1.CapInfo.Capability:= uCapability;
LEADTwainCapability1.CapInfo.ConType:= L_TWON_ONEVALUE;
LEADTwainCapability1.CapOneValue.OneValItemType:= uItemType;
LEADTwainCapability1.CapOneValue.OneValCapValue:= CapVal;
iRet:= LEADRasterTwain1.SetCapability2 (LEADTwainCapability1.DefaultInterface, L_LTWAIN_CAPABILITY_SET);
TwainSetCapability:= iRet;
end;
24. |
Run your program to test it. |