Windows Image Acquisition Fail

2k Views Asked by At

I try to acquire image from scanner using the code below

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

But it produce me this error:

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in Test.exe

Additional information: Error HRESULT E_FAIL has been returned from a call to a COM component.

Help help.

1

There are 1 best solutions below

7
On

First you need to find the scanner you want to use :

    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

then you take the picture :

    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")

Hope this help.

Refer to this Link From More Info Windows Image Acquisition

Edit Add reference to your project wiaaut.dll you can find it on C:\Windows\system32. And Imports WIA to your class.