In this article I will explain with an example, how to read QR code image in ASP.Net using C# and VB.Net.
In this article, ZXing.Net library will be used to read 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.
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
HTML Markup
The following HTML Markup consists of an ASP.Net FileUpload control, Button, a Label and an Image control.
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnRead" runat="server" Text="Read" OnClick="OnRead" /><br /><br />
<asp:Label runat="server" ID="lblQRCodeText"></asp:Label>
Reading QR code image using C# and VB.Net
When the Read Button is clicked, following event handler is executed.
Inside this event handler, the selected QR code Image file is read into Byte Array using the BinaryReader class object.
Next, the Byte Array is determined using the ReadAllBytes method of File class.
Then, Byte Array is saved in the MemoryStream object and then, converted to image URL using Base64 string.
Next, Bitmap is saved in the BitmapLuminanceSource object and then the object is converted to BinaryBitmap object.
Finally, the decoded value of QR code image is set to the Label control.
protected void OnRead(object sender, EventArgs e)
    string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
    Stream fs = FileUpload1.PostedFile.InputStream;
    BinaryReader br = new BinaryReader(fs);
    byte[] bytes = br.ReadBytes((Int32)fs.Length);
    using (MemoryStream ms = new MemoryStream(bytes))
        // Create Bitmap from selected file.
        using (Bitmap bitMap = new Bitmap(ms))
            // Read the QRCode.
            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;
Protected Sub OnRead(ByVal sender As Object, ByVal e As EventArgs)
    Dim fileName As String = Path.GetFileName(FileUpload1.PostedFile.FileName)
    Dim fs As Stream = FileUpload1.PostedFile.InputStream
    Dim br As BinaryReader = New BinaryReader(fs)
    Dim bytes As Byte() = br.ReadBytes(CType(fs.Length, Int32))
    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 Sub
Read QR Code Image in ASP.Net using C# and VB.Net