Delphi Sample: Acquire and save to BMP file

Top  Previous  Next

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.Acquire(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.