Search code examples
vb.netwia

Wia code won`t work with kodak scanmate i1120 scanner


I have re-written a program that scans a document and reads a barcode from the document that was written in vb6 and worked on windows xp.

This new program works fine on windows 10 with an old fujitsu fi-4129c2 scanner but I cant get it to work with a new scanmate i1120 scanner.

The error I get is on the following line :

MyImage = DirectCast(ConnectedScanner.Items(1).Transfer(WIA.FormatID.wiaFormatBMP), WIA.ImageFile)

and the error I get is :

Scan Error

I know that the code works as I have it working with the fujitsu scanner but I cant seem to figure out what value is giving me the error on the scanmate.

I have just tried it with the following three lines of code only and it still gives me the same error :

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

Solution

  • Turns out it was the WIA_DPS_PAGES setting for the scanner.

    I tried changing it using the following code :

    With ConnectedScanner.Items(1)
            .Properties("3096").Value = 1
            .Properties("6146").Value = 2 
            .Properties("6147").Value = 300 'dots per inch/horizontal
            .Properties("6148").Value = 300 'dots per inch/vertical
            .Properties("6154").Value = -50 'brightness
            .Properties("6155").Value = -50 ' contrast
        End With
    

    But this didn`t work so after a look at WIA Scanning via Feeder

    I converted the code on this page to vb and used the following Sub :

    Public Sub SetDeviceProperty(device As Device, propertyId As Integer, value As Object)
        Dim [property] As [Property] = FindProperty(device.Properties, propertyId)
        If [property] IsNot Nothing Then
            [property].let_Value(value)
        End If
    End Sub
    

    And changed the settings using :

    SetDeviceProperty(ConnectedScanner, 3096, 1)
    SetDeviceProperty(ConnectedScanner, 6146, 2)
    SetDeviceProperty(ConnectedScanner, 6147, 300)
    SetDeviceProperty(ConnectedScanner, 6148, 300)
    SetDeviceProperty(ConnectedScanner, 6154, -50)
    SetDeviceProperty(ConnectedScanner, 6155, -50)