VB.NET translation

Apr 1, 2016 at 12:24 AM
Edited Apr 1, 2016 at 12:29 AM
Hi,

I just came to share the VB.NET variant (on which I had trouble to convert at the handlers's part) so it can be helpful to others:
Imports System.Drawing.Imaging
Imports ADFScanner

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim _scanner = New ADFScan

        AddHandler _scanner.Scanning, AddressOf Me._scanner_Scanning
        AddHandler _scanner.ScanComplete, AddressOf Me._scanner_ScanComplete

        Dim selectedColor As ScanColor = ScanColor.Color
        Dim dpi As Integer = 150

        'some scanners have a problem if you set a lower DPI
        _scanner.BeginScan(selectedColor, dpi)
        'ADFScan will now raise a Scanning event for EACH document scanned.
        'then scan complete once there are no more documents to scan.
    End Sub

    Private Sub _scanner_ScanComplete(sender As Object, e As EventArgs)
        MessageBox.Show("Scan Complete")
    End Sub

    Private Sub _scanner_Scanning(sender As Object, e As WiaImageEventArgs)
        'e.ScannedImage is a System.Drawing.Image
        e.ScannedImage.Save("C:\TEMP\test.jpg", ImageFormat.Jpeg)
        'FILES ARE RETURNED AS BITMAPS
    End Sub

End Class
Also, don't forget:
  1. Copy "ADFScanner.dll" and "Interop.WIA.dll" to your project.
  2. Add a refference to those dll's (Right click project name > Add reference > Browse for the files).
  3. Again, right click project name and click on "Properties", then go to the "References" tab.
  4. Locate "ADFScanner" and "Interop.WIA".
  5. Click on each one to open the Properties panel. Set "Embed Interop Types" to "False" and "Copy Local" to "True", for both dll's.
Happy coding!!! :B
Marked as answer by smtrejo on 3/31/2016 at 5:24 PM