Howdy,
I am writing an application that needs to scan documents from a TWAIN scanner. For the most part, I will not know what kind of scanner will be installed on the computer.
I wanted to use FastTWAIN because 2 of our scanners can rip these pages out at 120ipm.
I only need to scan the documents at 150 dpi B&W.
We are using the application to archive paper medical records to a MS SQL database.
When I started to look into FastTWAIN, I was a little disappointed that you had to scan several batches of documents so it could figure out what configuration was the best.
My app needs to not write anything to the hard drive.
I have dropped FastTwain for now, but if there is a way to use it without needing to write to a hard drive I would be very interested.
Since I dropped FastTwain, I have gotten lost in the configuration part of using the scanner. I can select the source and scan images to a RasterImageList.
By default, I want the scanner to give the RasterImageList an image that is 150dpi B&W.
If the scanner has an ADF, then I want to check to see if there is paper in the feeder and then scan.
If the scanner is duplex capable, I want the pages to be scanned duplex.
I also want to auto deskew, remove blank pages, and clean the image up a little.
Our paper types vary greatly from yellow and pink onion paper to regular copier paper so I just want good middle of the road scan settings.
All of this needs to be done through the program if possible. I do not want the user to make any choices.
Thank you for any help you can provide.
Keith
Here is some code showing you my first attempts at setting the scanner configurations:
As you can see, I have commented all of this out.
Private Sub GetSetScannerConfiguration()
Try
'Dim twFastConfigs() As TwainFastConfiguration = _twainSession.FindConfiguration(1, TwainTransferMechanism.Memory, 5)
''ReDim twFastConfig(1)
'Dim fastConfigRes As TwainFindFastConfigurationResult
'_twainSession.EnableFastConfigurationEvent = False
''twFastConfig(0).TransferMechanism = TwainTransferMechanism.Memory
''twFastConfigs(0).ImageFormat = RasterImageFormat.Tif
''twFastConfigs(0).BitsPerPixel = 1
''twFastConfig(1).TransferMechanism = TwainTransferMechanism.Native
''twFastConfig(1).ImageFormat = RasterImageFormat.Tif
''twFastConfig(1).BitsPerPixel = 1
'fastConfigRes = _twainSession.FindFastConfiguration("d:\temp", TwainFastUserInterfaceFlags.None, 0, 1, twFastConfigs)
'Dim msg As String
'MessageBox.Show("FindFastConfig method was successful")
'msg = String.Format("Result Scan Configs count = {0}", fastConfigRes.Tested.Length)
'MessageBox.Show(msg)
'msg = "Transfer Mode = " + CStr(fastConfigRes.Tested(0).TransferMechanism) + Chr(13) + _
' "File Format = " + CStr(fastConfigRes.Tested(0).ImageFormat) + Chr(13) + _
' "Buffer Size = " + CStr(fastConfigRes.Tested(0).BufferSize) + Chr(13) + _
' "Required Time = " + CStr(fastConfigRes.Tested(0).RequiredTime) + Chr(13)
'MessageBox.Show(msg, "Tested Scan Configurations...")
'msg = "Transfer Mode = " + CStr(fastConfigRes.Best.TransferMechanism) + Chr(13) + _
' "File Format = " + CStr(fastConfigRes.Best.ImageFormat) + Chr(13) + _
' "Buffer Size = " + CStr(fastConfigRes.Best.BufferSize) + Chr(13) + _
' "Required Time = " + CStr(fastConfigRes.Best.RequiredTime) + Chr(13)
'MessageBox.Show(msg, "Best Scan Configurations...")
'Dim capType() As TwainCapabilityType = _twainSession.SupportedCapabilities
'Dim i As Integer
'twCap = _twainSession.GetCapability(TwainCapabilityType.ImageBitDepth, TwainGetCapabilityMode.GetValues)
'For i = 0 To capType.Length - 1
' Dim twCap As New TwainCapability
' Select Case capType(i)
' Case TwainCapabilityType.ImageTransferMechanism
' twCap.Information.ContainerType = TwainContainerType.OneValue
' twCap.Information.Type = TwainCapabilityType.ImageTransferMechanism
' twCap.OneValue.ItemType = TwainItemType.Int32
' twCap.OneValue.Value = TwainCapabilityValue.TransferMechanismMemory
' _twainSession.SetCapability(twCap, TwainSetCapabilityMode.Set)
' Case TwainCapabilityType.Duplex
' End Select
'
'Next
'_twainSession.EnableAutoFeed = True
'_twainSession.EnableDuplex = True
'_twainSession.ImageBitsPerPixel = 1
'_twainSession.XResolution = 150
'_twainSession.YResolution = 150
Catch ex As Exception
LogError(ex)
End Try
End Sub
Below is some of the code I already have in place.
Private Sub ScanImagestoList()
Try
_twainSession = New Twain.TwainSession
_twainSession.Startup(Me, "ABCD", "Scanner", "Version 1", " Scanner")
SelectScanner()
GetSetScannerConfiguration()
ScanPages()
'enable add and delete buttons
AddToolStripButton.Enabled = True
DeleteToolStripButton.Enabled = True
Catch ex As Exception
LogError(ex)
Finally
_twainSession.Shutdown()
End Try
End Sub
Private Sub SelectScanner()
'if there is only one TWAIN source, it is already selected as the scanner.
'This displays the select dialog box only when there are multiple sources
Try
If _twainSession.SourceInformation.Length > 1 Then
If _twainSession.SelectSource() <> Windows.Forms.DialogResult.OK Then
MessageBox.Show("Error selecting source")
End If
End If
Catch ex As Exception
LogError(ex)
End Try
End Sub
Private Sub ScanPages()
If _twainSession.Acquire(TwainUserInterfaceFlags.Modal) <> Windows.Forms.DialogResult.OK Then
MessageBox.Show("error acquring from source")
End If
End Sub
Private Sub twainSession_AcquirePage(ByVal sender As Object, ByVal e As Leadtools.Twain.TwainAcquirePageEventArgs) Handles _twainSession.AcquirePage
Try
Dim imageitem As New RasterImageListItem(e.Image, 1, "")
RasterImageList.Items.Add(imageitem)
UpdateImageCountLabel()
Catch ex As Exception
LogError(ex)
End Try
End Sub