Home > Uncategorized > Read a QR code in C# using the ZXing.net library

Read a QR code in C# using the ZXing.net library

qr

QR codes are all around us, and with a few lines of code you can take an image of a QR code, and interpet it as text. The same code also works with barcodes, and all these formats; UPC-A, UPC-E, EAN-8, EAN-13, Code 39, Code 93, Code 128, ITF, Codabar, MSI, RSS-14 (all variants), QR Code, Data Matrix, Aztec and PDF-417.

The code is open source at https://github.com/infiniteloopltd/ReadQRCode , but there’s not much to it; just these few lines of code;

const string imageUrl = “https://httpsimage.com/v2/c890b3a2-098b-41ab-bb9a-cc727bfc1a95.png”;
// Install-Package ZXing.Net -Version 0.16.5
var client = new WebClient();
var stream = client.OpenRead(imageUrl);
if (stream == null) return;
var bitmap = new Bitmap(stream);
IBarcodeReader reader = new BarcodeReader();
var result = reader.Decode(bitmap);
Console.WriteLine(result.Text);

 

Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: