Delphi Sample Program
The following Delphi example all that is required to do the following:
Check if TWAIN is installed.
Initialize the DTWAIN Dynamic Link Library.
Select a Source
Acquire a page using the Native transfer mode
Save page to a BMP file called "test.bmp"
Shut down any open TWAIN Source's and DTWAIN itself
___________________________________________________________
procedure TForm1.RetrieveDib(Sender: TObject);
var
SelectedSource: DTWAIN_SOURCE;
ErrStatus: DWORD;
AcquiredOk:DTWAIN_BOOL;
begin
{ Check for TWAIN availability }
if (DTWAIN_IsTwainAvailable) then
begin
{ Initialize DTWAIN }
if (DTWAIN_SysInitialize <> 0) then
begin
FileFlags:= DTWAIN_USENATIVE or DTWAIN_USENAME;
FileNames:= 'test.bmp'; { Name of file when image is acquired }
{ Select a Source }
SelectedSource := DTWAIN_SelectSource;
if SelectedSource <> 0 then
begin
{ Open the source and Acquire to File }
AcquiredOk := DTWAIN_AcquireFile(
SelectedSource,
PChar(FileNames),
DTWAIN_BMP,
FileFlags,
DTWAIN_PT_DEFAULT,
1,TRUE, TRUE,ErrStatus);
end;
DTWAIN_SysDestroy
end
end
end;
___________________________________________________________
That's all there is to it. To use DTWAIN with Delphi, your Delphi project must add the DTWAIN32.PAS that comes with DTWAIN to your project.
The documentation that comes with the DynaRithmic TWAIN Library discusses functions such as DTWAIN_AcquireFile in depth. It wasn't discussed here, but the goal of this small example is to show how simple it is to acquire images from a TWAIN device and save them to a file.
To acquire to the other file types other than BMP, the parameter that specifies DTWAIN_BMP can be any of the other file types such as DTWAIN_GIF, DTWAIN_JPEG, etc.. Therefore just 5 calls can save a file to any of many file types by just changing the third parameter to DTWAIN_AcquireFile.