Visual Basic Sample: Acquire and save to BMP file

Top  Previous  Next

The following Visual Basic function is 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

___________________________________________________________________

Private Sub ExampleFunction( )

 

Dim RetVal As Long

 

Rem Check for Twain

if DTWAIN_IsTwainAvailable Then

 

     Rem Initialize DTWAIN

    DTWAIN_SysInitialize

 

      Rem Acquire to a BMP file

      RetVal = DTWAIN_TwainSave(" -f test.bmp" )

 

      Rem Shut down DTWAIN

      DTWAIN_SysDestroy            

End If

EndSub

________________________________________________

 

Add the DTWAIN32.BAS interface to the Visual Basic project to define the DTWAIN functions, and that is all that's needed to compile the function correctly.  Note that this is function shows complete usage of DTWAIN from start to finish.  There are no other "hidden" DTWAIN calls or setup to do.  Of course, your VB application would more than likely be more advanced, however this example illustrates what can be done with just a few lines of code.

 

DTWAIN_IsTwainAvailable is only optional.  DTWAIN will still work correctly in a system that has no TWAIN drivers installed by returning an error if a selection of a TWAIN device is attempted.

 

The command-line function, DTWAIN_TwainSave takes a single argument that describes what is to be done to acquire an image.  A complete list of options are found in the DTWAIN_TwainSave command overview.