Windows 图像采集失败



我尝试使用以下代码从扫描仪获取图像

Dim CD As New WIA.CommonDialog
Dim F As WIA.ImageFile = CD.ShowAcquireImage(WIA.WiaDeviceType.UnspecifiedDeviceType)
F.SaveFile("C:TempWIA" + F.FileExtension)

但它给我带来了这个错误:

类型的未处理异常 "System.Runtime.InteropServices.COMException"发生在测试中.exe

其他信息:错误 HRESULT E_FAIL已从 调用 COM 组件。

帮助

帮助。

首先,您需要找到要使用的扫描仪:

    Dim DeviceID As String
    Dim class1 As CommonDialogClass = New CommonDialogClass
    Dim d As Device = class1.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, True, False)
    If (Not (d) Is Nothing) Then
        DeviceID = d.DeviceID
    End If

然后你拍照片:

    Dim manager As DeviceManager = New DeviceManagerClass
    Dim d1 As Device = Nothing
    For Each info As DeviceInfo In manager.DeviceInfos
        If (info.DeviceID = DeviceID) Then
            d1 = info.Connect
            Exit For
        End If
    Next
    Dim item As Item = d1.Items(1)
    Dim imagefile As WIA.ImageFile = CType(item.Transfer(), WIA.ImageFile)
    imagefile.SaveFile("D:IMg1.jpg")

希望这有帮助。

请参阅更多信息 Windows 图像采集中的此链接

编辑添加对项目的引用,wiaaut.dll您可以在 C:Windowssystem32 上找到它。Imports WIA你的班级。

最新更新