Visual Basic (.NET and above) Sample: Acquire and save to BMP file

Top  Previous  Next

The following Visual Basic (.NET and above) 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( )

 

   Private TwainOK As Integer

 

   Private MyDTwain As DTWAINAPI

   Private SelectedSource As Integer

   Private RetVal As Integer

   Dim FileName As String = "test.bmp"

 

   With MyDTwain

             Dim Status As Integer

 

             Rem Check if TWAIN is installed

             TwainOK = .DTWAIN_IsTwainAvailable( )

             SelectedSource = 0

             If TwainOK = 1 Then

 

                  Rem Initialize DTWAIN

                  TwainOK = .DTWAIN_SysInitialize( )

 

                   Rem Select a TWAIN device

                   SelectedSource = .DTWAIN_SelectSource( )

 

                   Rem Acquire to a file.

                   if SelectedSource <> 0 Then

                          RetVal = .DTWAIN_AcquireFile( SelectedSource, FileName, .DTWAIN_BMP,

                                                                                    .DTWAIN_USENATIVE+DTWAIN_USENAME,

                                                                                    .DTWAIN_PT_DEFAULT, 1, 1, Status )

                   End If

 

                   Rem shut down TWAIN system and DTWAIN.        

                  .DTWAIN_SysDestroy( )

              End If

       End With

   End Sub

___________________________________________________________

 

For Visual Basic .NET, all that is needed is to add the DTWAIN32_NET.VB file to your project.  This file contains the DTWAINAPI class which wraps the DTWAIN functions.