Wia扫描 [英] Wia Scanning

查看:97
本文介绍了Wia扫描的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从各种ADF扫描仪(主要是MFC的)扫描多页.我已经为此奋斗了大约一个星期,但收效甚微.我确实在twain下工作,但是,每个页面都是一个单独的tif文件.我想要 使用WIA并将其合并.我找到了一些代码,但是它是用以前的版本编写的,当我在2010年运行它时会产生错误.

I am attempting to scan in multiple pages from an ADF on a variety if scanners (Mostly MFC's). I have been fighting this for about a week with not much success. I do have it working under twain, however, each page is a separate tif file. I would like to use WIA and have them combined. I found some code, but it was written in a previous version and generates an error when I run it in 2010.

错误是:值不在预期范围内.

The error is :Value does not fall within the expected range.

这是选择wia设备的代码的第一部分.看来还可以.

 

'Choose Scanner
            Dim class1 As New CommonDialogClass()
            Dim d As Device = class1.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, True, False)
            If d IsNot Nothing Then
                Me.DeviceID = d.DeviceID
            Else
                'no scanner chosen
                Return
            End If

            Dim WiaCommonDialog As WIA.CommonDialog = New CommonDialogClass()
            Dim hasMorePages As Boolean = True
            Dim x As Integer = 0
            Dim numPages As Integer = 0
            While hasMorePages
                'Create DeviceManager
                Dim manager As DeviceManager = New DeviceManagerClass()
                Dim WiaDev As Device = Nothing
                For Each info As DeviceInfo In manager.DeviceInfos
                    If info.DeviceID = Me.DeviceID Then
                        Dim infoprop As WIA.Properties = Nothing
                        infoprop = info.Properties

                        'connect to scanner
                        WiaDev = info.Connect()

                        Exit For
                    End If
                Next

 

这是实际进行扫描的地方.我在出现错误的行上加粗并加了下划线.

                'Start Scan
                Dim img As WIA.ImageFile = Nothing
                Dim Item As WIA.Item = TryCast(WiaDev.Items(1), WIA.Item)
                'Try
                img = DirectCast(WiaCommonDialog.ShowTransfer(Item, wiaFormatTIFF, False), ImageFile) ' error occurs here

          

 

这是其余的内容.我认为这并没有真正的意义,但是我说过,这不是我的代码,所以我不确定.我对编程还是很陌生,只做了几个月.

 

 'Save to file
                Dim varImageFileName As String = "c:\test" & x.ToString() & ".tiff"
                If File.Exists(varImageFileName) Then
                    'file exists, delete it
                    File.Delete(varImageFileName)
                End If
                img.SaveFile(varImageFileName)
                numPages += 1

                img = Nothing
                'Catch ex As Exception
                'MessageBox.Show("Error: " & ex.Message)
                'Finally
                Item = Nothing
                'determine if there are any more pages waiting
                Dim documentHandlingSelect As WIA.Property = Nothing
                Dim documentHandlingStatus As WIA.Property = Nothing
                For Each prop As WIA.Property In WiaDev.Properties
                    If prop.PropertyID = WIA_PROPERTIES.WIA_DPS_DOCUMENT_HANDLING_SELECT Then
                        documentHandlingSelect = prop
                    End If
                    If prop.PropertyID = WIA_PROPERTIES.WIA_DPS_DOCUMENT_HANDLING_STATUS Then
                        documentHandlingStatus = prop

                    End If
                Next

                hasMorePages = False
                'assume there are no more pages
                If documentHandlingSelect IsNot Nothing Then
                    'may not exist on flatbed scanner but required for feeder
                    'check for document feeder

                    'If (WIA_DPS_DOCUMENT_HANDLING_SELECT.FEEDER <> 0) Then
                    '    hasMorePages = WIA_DPS_DOCUMENT_HANDLING_STATUS.FEED_READY
                    'End If

                    If (Convert.ToUInt32(documentHandlingSelect.Value) And WIA_DPS_DOCUMENT_HANDLING_SELECT.FEEDER) <> 0 Then
                        hasMorePages = ((Convert.ToUInt32(documentHandlingStatus.Value) And WIA_DPS_DOCUMENT_HANDLING_STATUS.FEED_READY) <> 0)
                    End If
                End If
                x += 1
                'End Try
            End While

感谢您在帮助我在此处发现问题或在其他地方提供工作代码示例的帮助.

Thank you for any assistance you can provide in either helping me identify the problem here or providing an example of working code somewhere else.

致谢.

 

 

推荐答案

您是否真的相信有人会使用该代码.购买一个像您一样的完整环境,然后提供帮助.

Do you really believe that somebody would go in that code. Buys a complete environment like yours and then gives help.

尝试创建一个不会产生相同错误而不依赖特殊硬件或其他来源的小片段.

Try to create a little snippet which does produce the same error without to be depended from special hardware or other sources.

最后,然后以快速识别的方式告诉您错误发生的位置.

And as last tell then where the error occurs in a quick recognizable way. 

现在看来,似乎有人命令您查看该论坛,并且您创建了一些您肯定没有真正帮助的东西.

Now it look more that somebody ordered you to look at the forum and you created something for which you for sure get no real help.


这篇关于Wia扫描的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆