Get a Fast Twain Scan from a Scanner (Visual Basic)
Take the following steps to start a project and to add some code to find the fastest configuration for your scanner using the LEADTOOLS Fast TWAIN feature:
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 Object Library to your project. On the Project pull-down menu, use the References option, and select the LEAD Raster 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
5. |
Add the following code to the main form's Load procedure: |
Set RasterTwain = New LEADRasterTwain
RasterTwain.InitSession hWnd
RasterTwain.EnableMethodErrors = False
' Unlock Document support.
' Note that this is a sample key, which will not work in your toolkit.
RasterTwain.UnlockSupport L_SUPPORT_DOCUMENT, "TestKey"
6. |
Add the following code to the main form's Unload procedure: |
RasterTwain.EndSession
Set RasterTwain = Nothing
7. |
At the top of your main form, add 3 command buttons as following: |
|
|
Name |
Caption |
|
cmdSelectSource |
Select Source |
|
cmdFindFastConfig |
Find Fast Config |
|
cmdAcquireFastConfig |
Acquire Fast Config |
8. |
Code the "Select Source" control's Click procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code. |
Private Sub cmdSelectSource_Click()
RasterTwain.SelectSource
End Sub
9. |
Code the "Find Fast Config" control's Click procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code. |
Private Sub cmdFindFastConfig_Click()
RasterTwain.UserFastConfigsCount = 0
RasterTwain.EnableFastConfigEvent = False
nRet = RasterTwain.FindFastConfig ("c:\temp", L_LTWAIN_SHOW_USER_INTERFACE Or L_LTWAIN_USE_THREAD_MODE, 8, 5)
If nRet = 0 Then
MsgBox "Find Fast Configuration process completed."
Else
MsgBox "An error occurred during the Finding Fast Configuration process."
End If
End Sub
10. |
Code the "Acquire Fast Config" control's Click procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code. |
Private Sub cmdAcquireFastConfig_Click()
RasterTwain.FastTransferMode = RasterTwain.BestFastConfig.TransferMode
RasterTwain.FastFormat = RasterTwain.BestFastConfig.FileFormat
RasterTwain.FastBitsPerPixel = RasterTwain.BestFastConfig.BitsPerPixel
RasterTwain.FastBufferSize = RasterTwain.BestFastConfig.BufferSize
RasterTwain.FastUsePreferredBufferSize = True
RasterTwain.EnableAcquireMultiEvent = False
nRet = RasterTwain.AcquireMulti ("c:\temp\test", L_LTWAIN_SHOW_USER_INTERFACE, True)
If nRet = 0 Then
MsgBox "Image acquisition using the Fast TWAIN Configuration is completed."
Else
MsgBox "An error occurred while acquiring images using the Fast TWAIN Configuration."
End If
End Sub
11. |
Save your project and run your program to test it. |