Get a Fast Twain Scan from a Scanner (Delphi)
Take the following steps to get fast twain scan using the LEADTOOLS Fast TWAIN features:
1. |
Start Delphi. | |
2. |
On the Delphi 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 and Add the LEAD TWAIN control from the VCL toolbar to your Main Form. | |
4. |
Add 3 buttons to your form and name them as follows: | |
|
Name |
Caption |
|
btnSelectSource |
Select Source |
|
btnFindFastConfig |
Find Fast Config |
|
btnAcquireFastConfig |
Acquire Fast Config |
5. |
Define the following variable in the private section of Form1: |
BestConfig: FASTCONFIG;
6. |
Handle the Form1 OnCreate event, and code the FormCreate procedure as follows: |
procedure TForm1.FormCreate(Sender: TObject);
var
nRet: L_INT;
begin
LEADTwain1.EnableMethodErrors := False;
LEADTwain1.ManName:= 'LEAD Technologies, Inc.';
LEADTwain1.ProdFamily:= 'LEAD Test Applications';
LEADTwain1.Version:= 'Version 1.0';
LEADTwain1.AppName:= 'TWAIN Test Application';
nRet:= LEADTwain1.InitSession ( Handle );
if ( nRet <> SUCCESS ) then
begin
ShowMessage ( 'Failure to Initialize TWAIN' );
Exit;
end;
LEADTwain1.EnableMethodErrors := True;
{ Unlock Document support.
Note that this is a sample key, which will not work in your toolkit. }
LEADTwain1.UnlockSupport ( L_SUPPORT_DOCUMENT, ‘TestKey' );
end;
7. |
Handle the Form1 OnClose event, and code the FormClose procedure as follows: |
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
LEADTwain1.EndSession ( );
end;
8. |
Handle the btnSelectSource OnClick event, and code the btnSelectSourceClick procedure as follows: |
procedure TForm1.btnSelectSourceClick(Sender: TObject);
begin
LEADTwain1.SelectSource ( );
end;
9. |
Handle the btnFindFastConfig OnClick event, and code the btnFindFastConfigClick procedure as follows: |
procedure TForm1.btnFindFastConfigClick(Sender: TObject);
var
nRet: L_INT;
nTestConfigsCount: L_INT;
pTestConfigs: pFASTCONFIG;
begin
nTestConfigsCount:= 0;
pTestConfigs:= Nil;
LEADTwain1.EnableMethodErrors := False;
nRet:= LEADTwain1.FindFastConfig ( 'c:\temp', LTWAIN_SHOW_USER_INTERFACE Or LTWAIN_USE_THREAD_MODE,
8,
5,
Nil,
0,
@pTestConfigs,
@nTestConfigsCount,
@BestConfig );
if (nRet = SUCCESS) then
ShowMessage ( 'Find Fast Configuration process completed' )
else
ShowMessage ( 'An error occurred during the Finding Fast Configuration process.' );
LEADTwain1.EnableMethodErrors := True;
end;
10. |
Handle the btnAcquireFastConfig OnClick event, and code the btnAcquireFastConfigClick procedure as follows: |
procedure TForm1.btnAcquireFastConfigClick(Sender: TObject);
var
nRet: L_INT;
begin
LEADTwain1.EnableMethodErrors := False;
nRet:= LEADTwain1.AcquireMulti ( 'c:\temp\testconfig.tif',
LTWAIN_SHOW_USER_INTERFACE Or LTWAIN_USE_THREAD_MODE,
BestConfig.uTransferMode,
BestConfig.nFileFormat,
BestConfig.nBitsPerPixel,
True,
BestConfig.ulBufferSize,
True );
if ( nRet = SUCCESS ) then
MessageBox ( Handle, 'Image acquisition using the Fast TWAIN Configuration is completed.', 'Fast Config', MB_OK )
else
MessageBox ( Handle, 'An error occurred while acquiring images using the Fast TWAIN Configuration.', 'Fast Config', MB_OK );
LEADTwain1.EnableMethodErrors := True;
end;
11. |
At the beginning of the Unit1 file, add LEADTyp and LEADDef to the uses section. |
12. |
Run your program to test it. |