All of that works very well.
The problem I'm running into is after the first image is acquired via VSTwain1.AcquireModal(), all subsequent images ignore the previous settings. For example, if my settings are to scan in black and white at 200 dpi the first page will scan at those settings, but the 2nd, 3rd, etc scans will be in full color at 300 dpi (default settings).
Is there some magic that happens with AcquireModal() when scanning from a flatbed?
I've been looking through the SDK docs and the forums and I can't find anything that mentions the settings being reset.
What can I do to prevent this? Am I going about this the wrong way? This happens on my HP J4580 and the HP PSC 1401 we have which is flatbed only.
Here's the code:
Code: Select all
Private Shared Function ScanFromFlatbed(ByVal strFileName As String, Optional ByVal bShowSelectDevice As Boolean = True) As Boolean If bShowSelectDevice AndAlso Not VSTwain1.SelectSource() Then Return False End If MessageBox.Show("Place the " & IIf(ScanningMultiplePages, "first ", String.Empty) & "document on the scanning device then click OK to start scanning.", "Waiting for Document", MessageBoxButtons.OK, MessageBoxIcon.Information) VSTwain1.ShowUI = False VSTwain1.DisableAfterAcquire = True VSTwain1.TransferMode = TransferMode.Native VSTwain1.MaxImages = 1 VSTwain1.AutoCleanBuffer = True VSTwain1.OpenDataSource() DetectDeviceType() SetCapabilities() VSTwain1.XferCount = 1 VSTwain1.PdfDocumentInfo.Author = "MyApplicationNameHere" VSTwain1.PdfDocumentInfo.Creator = "VintaSoftTWAIN.NET v" & VSTwain1.Version VSTwain1.PdfImageCompression = PdfImageCompression.Auto VSTwain1.PdfMultiPage = True Dim bDoneScanning As Boolean = False Dim bRescanning As Boolean = False While Not bDoneScanning If VSTwain1.AcquireModal() Then Try VSTwain1.SaveImage(0, strFileName) Catch ex As TwainException WriteToDebugFile(ex.ToString) MessageBox.Show(ex.Message, "Scanning Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) End Try If ScanningMultiplePages Then ' prompt the user to see if there are more pages left to scan If MessageBox.Show("Do you have any more pages to append to this document?", "Multi-page Flatbed Scanning", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then ' we need to pause so the user can place the next original on the scanner MessageBox.Show("Place the next document on the scanning device then click OK to continue.", "Waiting for Next Document", MessageBoxButtons.OK, MessageBoxIcon.Information) bRescanning = True Else bDoneScanning = True bRescanning = False End If Else bDoneScanning = True End If ElseIf bRescanning Then ' ignore the acquire failure bRescanning = False Else Return False End If End While Return True End Function
One part of the code that you may notice is this:
Code: Select all
ElseIf bRescanning Then ' ignore the acquire failure bRescanning = False