read code 39 barcode with vb.net
<p>My goal with this project is to create a windows form application using VB.net to read a barcode from an image (form a file for now, taken with a webcam later) and write the text to a textbox.  I've found plenty of examples of how to decode bar codes using the Zxing library for pretty much every language except vb.net.  I have an image which contains a code 39 (I believe) bar code.  </p>

<p><a href="https://i.stack.imgur.com/12bLo.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/12bLo.jpg" alt="enter image description here"></a></p>

<p>After adding a reference to Zxing.dll and importing the desired namespace, I have this:</p>

<pre><code>Imports ZXing.OneD
Public Class Form2
    Private webcam As WebCam
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        webcam = New WebCam()
        webcam.InitializeWebCam(imgVideo)
        webcam.Start()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        imgCapture.Image = imgVideo.Image 'I plan to use this later


        Dim reader As New ZXing.OneD.Code39Reader
        Dim image1 As Bitmap
        image1 = Image.FromFile("C:\Capture.jpg") 'this is the image I'm using for testing purposes

        reader.decode(image1)
    End Sub
End Class
</code></pre>

<p>the line <code>reader.decode(image1)</code> generates an error: </p>

<pre><code>"Error  1   Value of type 'System.Drawing.Bitmap' cannot be converted to 'ZXing.BinaryBitmap'"
</code></pre>

<p>Clearly, I'm dabbling with things I don't yet understand... so I'm begging for help!  I'm using Visual Studio 2010 Express.</p>

<p>I've changed it yet again.  this code generates no error, yet it returns nothing.</p>

<pre><code>Imports ZXing
Imports ZXing.OneD
Public Class Form2
    Private webcam As WebCam
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        webcam = New WebCam()
        webcam.InitializeWebCam(imgVideo)
        webcam.Start()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        imgCapture.Image = imgVideo.Image 'I plan to use this later

        Dim reader As Code39Reader = New Code39Reader
        Dim image1 As Bitmap = New Bitmap("C:\Capture.bmp")
        Dim bitmapBytes As Byte()
        Using stream As New System.IO.MemoryStream
            image1.Save(stream, image1.RawFormat)
            bitmapBytes = stream.GetBuffer
        End Using
        Dim Lumin As LuminanceSource = New RGBLuminanceSource(bitmapBytes, image1.Width, image1.Height, bitmapFormat:=RGBLuminanceSource.BitmapFormat.RGB24)

        Dim HBin As Common.HybridBinarizer = New Common.HybridBinarizer(Lumin)
        Dim Bitm As BinaryBitmap = New BinaryBitmap(HBin)
        Dim res As String = reader.decode(Bitm).Text
    End Sub
End Class
</code></pre>

<p><strong>EDIT*</strong>
This is the working solution.  Thanks for the help guys!</p>

<pre><code>Imports ZXing
Imports ZXing.OneD
Imports System.IO
Public Class Form2
    Private webcam As WebCam
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        webcam = New WebCam()
        webcam.InitializeWebCam(imgVideo)
        webcam.Start()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        imgCapture.Image = imgVideo.Image 'I plan to use this later
        Dim reader As New ZXing.BarcodeReader
        Dim image1 As Bitmap
        image1 = Image.FromFile("C:\Capture.bmp")
        Dim res As Result = reader.Decode(image1)
        MsgBox(res.Text)
    End Sub

    Public Function GetRGBValues(ByVal Bmp As Bitmap) As Byte()
        Dim Rect As New Rectangle(0, 0, bmp.Width, bmp.Height)
        Dim BmpData As System.Drawing.Imaging.BitmapData = Bmp.LockBits(Rect, System.Drawing.Imaging.ImageLockMode.ReadOnly, Bmp.PixelFormat)
        Dim Ptr As IntPtr = BmpData.Scan0
        Dim Bytes As Integer = BmpData.Stride * Bmp.Height
        Dim RgbValues As Byte() = New Byte(Bytes - 1) {}
        System.Runtime.InteropServices.Marshal.Copy(Ptr, RgbValues, 0, Bytes)
        Bmp.UnlockBits(BmpData)
        Return RgbValues
    End Function
End Class
</code></pre>