How to generate and read QR code in

Posted by Anuraj on Monday, June 24, 2013 Reading time :1 minute

.Net ASP.Net Visual Studio Windows Forms Windows Phone

QR code (abbreviated from Quick Response Code) is the trademark for a type of matrix barcode (or two-dimensional barcode) first designed for the automotive industry in Japan; a barcode is an optically machine-readable label that is attached to an item and that records information related to that item: The information encoded by a QR code may be made up of four standardized types (“modes”) of data (numeric, alphanumeric, byte / binary, Kanji) or, through supported extensions, virtually any type of data. - Wikipedia.

Today I found a nice library which helps to create and read the QR code, - is a port of ZXing, an open-source, multi-format 1D/2D barcode image processing library originally implemented in Java. You can find more details and source code from the codeplex website.

You can install ZXing.Net using Package Manager console.

Install-Package ZXing.Net 

You can generate QR code using following code

var writer = new BarcodeWriter();
writer.Format = BarcodeFormat.QR_CODE;
var result = writer.Write("");
var barcodeBitmap = new Bitmap(result);
    (context.Response.OutputStream, ImageFormat.Jpeg);
context.Response.ContentType = "image/jpeg";

You can find details about the Barcode Contents from here. And you can read / decode the QR code using following code.

var reader = new BarcodeReader();
//Saving the uploaded image and reading from it
var fileName =
    Path.Combine(Request.MapPath("~/Imgs"), "QRImage.jpg");
var result = reader.Decode(new Bitmap(fileName));

Here is the QR code generated using the code

dotnetthoughts - QR Code

Happy Programming.

What do you think? I would like to hear your thoughts, suggestions, and questions in the comments section below.

Did you like this article? Share it with your friends

Facebook Twitter Google+ LinkedIn Reddit StumbleUpon

BMC logoBuy me a coffee

Copyright © 2019 - Anuraj P. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Hosted with ❤ by GitHub