Available in the LEADTOOLS Imaging toolkit. |
Acquiring an Image (Visual Basic)
Take the following steps to start a project and to add some code that acquires an image from a TWAIN source:
1. |
Start Visual Basic. |
2. |
Add the LEAD RasterView Control to your project. On the Project pull-down menu, use the Components option, and select the LEAD Main ActiveX Control. |
3. |
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. |
|
On the Project pull-down menu, use the References option, and select the LEAD Raster Variant Object Library. |
4. |
Add the following code to the general declarations section of your project: |
Public TwainCap As New LEADTwainCapability_U
Public WithEvents RasterTwain As LEADRasterTwain_U
Public nXferMode As Integer
Public nRet As Integer
5. |
Add the following code to the main form's Load procedure: |
Set RasterTwain = New LEADRasterTwain_U
RasterTwain.InitSession hWnd
File.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 six Command Buttons and three Option Buttons and name them as follows: |
|
|
Name |
Caption |
|
OK |
OK |
|
Cancel |
Cancel |
|
Acquire |
Acquire |
|
SelectSource |
SelectSource |
|
CmdSaveTemplate |
Save Template File |
|
CmdLoadTemplate |
Load Template File |
|
Native |
Native |
|
MemBuf |
Memory Buffered |
|
File |
File |
|
|
|
8. |
Code the OK 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 OK_Click()
Unload Me
End Sub
9. |
Code the Cancel 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 Cancel_Click()
Unload Me
End Sub
10. |
Code the Acquire control's Click procedure as follows: |
Private Sub Acquire_Click()
RasterTwain.Acquire L_LTWAIN_SHOW_USER_INTERFACE
End Sub
11. |
Code the SelectSource control's Click procedure as follows: |
Private Sub SelectSource_Click()
RasterTwain.SelectSource
End Sub
12. |
Code the CmdSaveTemplate control's Click procedure as follows: |
Private Sub cmdSaveTemplate_Click()
nRet = RasterTwain.SaveTemplate("c:\test.ltt")
End Sub
13. |
Code the cmdLoadTemplate control's Click procedure as follows: |
Private Sub cmdLoadTemplate_Click()
nRet = RasterTwain.LoadTemplate("c:\test.ltt")
End Sub
14. |
Code the Native option control's Click procedure as Follows: |
Private Sub Native_Click()
Dim CapVal As New LEADRasterVariant_U
nXferMode = L_TWSX_NATIVE
CapVal.Type = VALUE_USHORT
CapVal.LongValue = nXferMode
TwainSetCapability L_ICAP_XFERMECH, CapVal, L_TWTY_UINT16
End Sub
15. |
Code the MemBuf Option control's Click procedure as follows: |
Private Sub MemBuf_Click()
Dim CapVal As New LEADRasterVariant_U
nXferMode = L_TWSX_MEMORY
CapVal.Type = VALUE_USHORT
CapVal.LongValue = nXferMode
TwainSetCapability L_ICAP_XFERMECH, CapVal, L_TWTY_UINT16
End Sub
16. |
Code the File Option control's Click procedure as follows: |
Private Sub File_Click()
Dim CapVal As New LEADRasterVariant_U
nXferMode = L_TWSX_FILE
CapVal.Type = VALUE_USHORT
CapVal.LongValue = nXferMode
TwainSetCapability L_ICAP_XFERMECH, CapVal, L_TWTY_UINT16
RasterTwain.FileTransferName = "c:\twain.bmp"
End Sub
17. |
Code RasterTwain object’s procedure as follows: |
Private Sub RasterTwain_AcquirePageEvent(ByVal pBitmap As Long)
MsgBox "Acquisition of Image Done"
If
File.Value = False Then
LEAD1.InsertBitmapListItem -1, pBitmap
End
If
End Sub
18. |
Add this Function to the Project: |
Public Function TwainSetCapability(uCapability As Integer, CapVal As LEADRasterVariant_U, uItemType As Integer) As Integer
Dim iRet As Integer
TwainCap.EnableMethodErrors = False
TwainCap.CapInfo.Capability = uCapability
TwainCap.CapInfo.ConType = L_TWON_ONEVALUE
TwainCap.CapOneValue.OneValItemType = uItemType
TwainCap.CapOneValue.OneValCapValue = CapVal
iRet = RasterTwain.SetCapability2(TwainCap, L_LTWAIN_CAPABILITY_SET)
TwainSetCapability = iRet
End Function
19. |
Run your program to test it. |