In this article I will explain with an example, how to read QR code from image in Windows Forms (WinForms) Application using C# and VB.Net
This article will make use of ZXing.Net library for reading QR code image.
Download ZXing.Net package
You will need to install the ZXing.Net package using the following command.
Install-Package ZXing.Net -Version 0.16.9
For more details and documentation on ZXing.Net library, please refer following link.
Form Design
The following Form consists of a Button and a Label control.
Read QRCode from Image in Windows Forms using C# and VB.Net
You will need to import the following namespaces.
using System.IO;
using System.Drawing;
using ZXing;
using ZXing.Common;
Imports System.IO
Imports System.Drawing
Imports ZXing
Imports ZXing.Common
Reading QR code image using C# and VB.Net
The following event handler is executed, when the Read Button is clicked.
Inside this event handler, an instance of OpenFileDialog class is created.
Then, after selecting the file using the OpenFileDialog Box, the file name is read from the FileName property of the OpenFileDialog Box.
Next, the Byte Array is determined using the ReadAllBytes method of File class.
Then, Byte Array is saved in the MemoryStream object and then, Bitmap object is created and the MemoryStream object is saved to it.
Next, Bitmap is saved in the BitmapLuminanceSource object and then, the source is converted to BinaryBitmap object.
Finally, the decoded value of QR code image is read using the MultiFormatReader class and set to the Label control.
private void OnRead(object sender, EventArgs e)
    OpenFileDialog openFileDialog1 = new OpenFileDialog();
    openFileDialog1.Filter = "QR Code | *.jpg; *.jpeg; *.gif; *.bmp; *.png";
    if (openFileDialog1.ShowDialog() == DialogResult.OK)
        // Read selected file as Byte Array.
        byte[] bytes = File.ReadAllBytes(openFileDialog1.FileName);
        using (MemoryStream ms = new MemoryStream(bytes))
            // Create Bitmap from selected file.
            using (Bitmap bitMap = new Bitmap(ms))
                // Read the QRCode Image.
                BitmapLuminanceSource source = new BitmapLuminanceSource(bitMap);
                BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));
                // Reader object accept BinaryBitmap and decode it.
                Result result = new MultiFormatReader().decode(binaryBitmap);
                lblQRCodeText.Text = result.Text;
Private Sub OnRead(sender As Object, e As EventArgs) Handles btnRead.Click
    Dim openFileDialog1 As OpenFileDialog = New OpenFileDialog()
    openFileDialog1.Filter = "QR Code | *.jpg; *.jpeg; *.gif; *.bmp; *.png"
    If openFileDialog1.ShowDialog() = DialogResult.OK Then
        'Read selected file as Byte Array.
        Dim bytes As Byte() = File.ReadAllBytes(openFileDialog1.FileName)
        Using ms As MemoryStream = New MemoryStream(bytes)
            ' Create Bitmap from selected file.
            Using bitMap As Bitmap = New Bitmap(ms)
                ' Read the QRCode.
                Dim source As BitmapLuminanceSource = New BitmapLuminanceSource(bitMap)
                Dim binaryBitmap As BinaryBitmap = New BinaryBitmap(New HybridBinarizer(source))
                'Reader object accept BinaryBitmap and decode it.
                Dim result As Result = New MultiFormatReader().decode(binaryBitmap)
                lblQRCodeText.Text = result.Text
            End Using
        End Using
    End If
End Sub
Read QRCode from Image in Windows Forms using C# and VB.Net