Using the Fast TWAIN Feature (Visual Basic)

Take the following steps to start a project and to add some code that acquires the images using Fast Twain:

1.

Start Visual Basic.

2.

Add the LEAD RasterTwain Object Library and LEAD Raster Variant Object Library to your project.

 

On the Project pull-down menu, use the References option, and select the LEAD RasterTwain Object Library (14.5).

 

On the Project pull-down menu, use the References option, and select the LEAD Raster Variant Object Library (14.5).

3.

Add the LEAD Raster IO Object Library to your project. On the Project pull-down menu, use the References option, and select the LEAD Raster IO Object Library (14.5).

4.

Add the following code to the general declarations section of your project:

 

Public TwainCap As New LEADTwainCapability
Public WithEvents RasterTwain As LEADRasterTwain
Public nXferMode As Integer
Public nRet As Integer
Public RasterIO As LEADRasterIO

5.

Add the following code to the main form's Load procedure:

Set RasterTwain = New LEADRasterTwain
RasterTwain.InitSession hWnd
RasterTwain.EnableMethodErrors = False
optMemory.Value = True

6.

Add the following code to the main form's Unload procedure:

 

RasterTwain.EndSession

7.

At the top of your main form, add 1 check box

 

Name

Caption

 

chkUseBufferSize

Use Buffer Size

8.

Add the following radio buttons:

 

Name

Caption

 

optNative

Native Mode

 

optMemory

Memory Mode

9.

Add the following button:

 

Name

Caption

 

cmdAcquire

Fast Acquire

10.

Add the two text boxes and name them as follows:

txtBufferSize

txtFName

11.

Code the Fast Acquire control's Click procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code.

 

If optMemory.Value = True Then
   RasterTwain.FastTransferMode = L_LTWAIN_BUFFER_MODE
   RasterTwain.FastFormat = FILE_CCITT_GROUP4
Else
   RasterTwain.FastTransferMode = L_LTWAIN_NATIVE_MODE
   RasterTwain.FastFormat = FILE_TIF
End If

RasterTwain.FastBitsPerPixel = 1
RasterTwain.FastUsePreferredBufferSize = chkUseBufferSize.Value
RasterTwain.FastBufferSize = Val(txtBufferSize.Text)

nRet = RasterTwain.AcquireMulti(txtFName.Text, L_LTWAIN_SHOW_USER_INTERFACE Or L_LTWAIN_USE_THREAD_MODE, True)
If nRet = 0 Then
   MsgBox "Fast Scanning process completed successfully..."
Else
   MsgBox "The AcquireMulti method failed, Error = " + Str(nRet)
End If

12.

Save your project and run your program to test it.