Victor Image Processing Library How-to Tips
Control a TWAIN ADF Scanner
The control of the ADF scanner is straight forward.
In general, the steps are:
- open the TWAIN driver
- set the scan conditions
- enable the document feeder
- verify that pages are loaded
- scan the images
for each image scanned
- save for future use
- release the image buffer when done with it
- close the TWAIN driver
|
In this example we scan as many pages as are in the document feeder, but no more than five. Each image is saved as a separate page in a multipage TIFF file.
Hide the TWAIN user interface and with our application we set the scanning conditions.
|
| | Scan Condition | | Setting |
| | pixel type | | 1-bit black and white |
| | brightness | | 0 (midrange) |
| | contrast | | 0 (midrange) |
| | horizontal resolution | | 200 dpi |
| | vertical resolution | | 200 dpi |
| | area to scan | | 3 inches wide x 2 inches high |
scanwithADF - the Visual Basic Source Code
Requires Victor Image Processing Library for 32-bit Windows v 5.3 or higher.
Type imgdes
ibuff As Long
stx As Long
sty As Long
endx As Long
endy As Long
buffwidth As Long
palette As Long
colors As Long
imgtype As Long
bmh As Long
hBitmap As Long
End Type
Type RECT
left As Long
top As Long
right As Long
bottom As Long
End Type
Type TWAIN_ONEVALUE
val As Integer
End Type
Type TWAIN_ENUMTYPE
tarray(17) As Integer
nelems As Integer
currentIndex As Integer
defaultIndex As Integer
End Type
Type TWAIN_RANGE
min As Integer
max As Integer
stepSize As Integer
currentVal As Integer
defaultVal As Integer
End Type
Type TWAIN_CAP_DATA
conType As Integer
oneValue As TWAIN_ONEVALUE
enumType As TWAIN_ENUMTYPE
range As TWAIN_RANGE
End Type
Global Const TWUN_INCHES = 0
Global Const TWON_ARRAY = 3
Global Const TWON_ENUMERATION = 4
Global Const TWON_ONEVALUE = 5
Global Const TWON_RANGE = 6
Global Const TWPT_BW = 0
Global Const TWPT_GRAY = 1
Global Const TWPT_RGB = 2
Global pageno As Integer
Declare Sub freeimage Lib "VIC32.DLL" (image As imgdes)
Declare Function savetifpage Lib "VIC32.DLL" (ByVal fname As String, srcimg As imgdes, ByVal cmp As Long, ByVal page As Long) As Long
Declare Sub TWclose Lib "VICTW32.DLL" ()
Declare Function TWgetfeeder Lib "VICTW32.DLL" (ByVal hWnd As Long, ByRef feederIsEnabled As Long, ByRef feederHasPaper As Long) As Long
Declare Function TWopen Lib "VICTW32.DLL" (ByVal hWnd As Long) As Long
Declare Function TWscancountimages Lib "VICTW32.DLL" (ByVal hWnd As Long, ByRef desimg As imgdes, ByRef pRect As RECT, ByVal showIU As Long, ByVal maxPages As Long, ByVal saveScan As Long) As Long
Declare Function TWsetbrightness Lib "VICTW32.DLL" (ByVal hWnd As Long, ByRef brightness As TWAIN_CAP_DATA) As Long
Declare Function TWsetcontrast Lib "VICTW32.DLL" (ByVal hWnd As Long, ByRef contrast As TWAIN_CAP_DATA) As Long
Declare Function TWsetfeeder Lib "VICTW32.DLL" (ByVal hWnd As Long, ByVal enableFeeder As Long) As Long
Declare Function TWsetmeasureunit Lib "VICTW32.DLL" (ByVal hWnd As Long, ByRef typeUnit As TWAIN_CAP_DATA) As Long
Declare Function TWsetpixeltype Lib "VICTW32.DLL" (ByVal hWnd As Long, ByRef pixelType As TWAIN_CAP_DATA) As Long
Declare Function TWsetxresolution Lib "VICTW32.DLL" (ByVal hWnd As Long, xres As TWAIN_CAP_DATA) As Long
Declare Function TWsetyresolution Lib "VICTW32.DLL" (ByVal hWnd As Long, yres As TWAIN_CAP_DATA) As Long
Public Function scanwithADF(hWnd As Long) As Long
Dim rcode As Long
Dim gsimage As imgdes
Dim srect As RECT
Dim showUI As Long
Dim maxpages As Long
Dim unit_data As TWAIN_CAP_DATA
Dim reso_data As TWAIN_CAP_DATA
Dim pixel_data As TWAIN_CAP_DATA
Dim bright_data As TWAIN_CAP_DATA
Dim feederIsEnabled As Long
Dim feederHasPaper As Long
rcode = TWopen(hWnd)
If (rcode = NO_ERROR) Then
unit_data.oneValue.val = TWUN_INCHES
unit_data.conType = TWON_ONEVALUE
reso_data.oneValue.val = 200
reso_data.conType = TWON_ONEVALUE
pixel_data.oneValue.val = TWPT_BW
pixel_data.conType = TWON_ONEVALUE
bright_data.oneValue.val = 0
bright_data.conType = TWON_ONEVALUE
rcode = TWsetmeasureunit(hWnd, unit_data)
rcode = TWsetxresolution(hWnd, reso_data)
rcode = TWsetyresolution(hWnd, reso_data)
rcode = TWsetbrightness(hWnd, bright_data)
rcode = TWsetcontrast(hWnd, bright_data)
rcode = TWsetpixeltype(hWnd, pixel_data)
srect.left = 0
srect.top = 0
srect.right = 3000
srect.bottom = 2000
showUI = 0
pageno = 0
maxpages = 5
feederIsEnabled = 1
rcode = TWsetfeeder(hWnd, feederIsEnabled)
rcode = TWgetfeeder(hWnd, feederIsEnabled, feederHasPaper)
If (feederIsEnabled <> 0) Then
If (feederHasPaper <> 0) Then
rcode = TWscancountimages(hWnd, gsimage, srect, showUI, maxpages, AddressOf savescanedpagetotiff)
End If
End If
TWclose
End If
scanwithADF = rcode
End Function
Public Function savescanedpagetotiff(jimage As imgdes) As Long
Dim rcode As Long
Dim Filename As String
Filename = "testadf.tif"
rcode = savetifpage(Filename, jimage, 0, pageno)
If (rcode = NO_ERROR) Then
pageno = pageno + 1
End If
freeimage jimage
savescanedpagetotiff = rcode
End Function
Victor Image Processing Library homepage |
Victor Product Summary |
more source code
Copyright © 1995 - 2002 Catenary Systems Inc. All rights reserved. Victor Image Processing Library is a trademark of Catenary Systems.