How to generate QR barcodes in C#
QR barcodes are machine-readable optical labels that contain certain information. Today we will be looking into how to generate QR codes with the use of the ZXing.Net library.
First you will need to download the ZXing.Net library from zxingnet.codeplex.com. Extract the contents of the file you have downloaded and reference the library that fits your needs in your project.
Using the example code below you will now be able to create your own QR codes.
1 2 3 4 5 6 7 8 9 10 | public Bitmap GenerateQR(int width, int height, string text) { var bw = new ZXing.BarcodeWriter(); var encOptions = new ZXing.Common.EncodingOptions() { Width = width, Height = height, Margin = 0 }; bw.Options = encOptions; bw.Format = ZXing.BarcodeFormat.QR_CODE; var result = new Bitmap(bw.Write(text)); return result; } |
Example: Calling the following method will return a Bitmap object which you can save using the Bitmap’s Bitmap.Save() method or simply display it within your application.
1 | GenerateQR(200, 200, "http://www.fluxbytes.com/csharp/generating-qr-barcode-in-c/"); |
I get the below error where the image is supposed to be..
System.Drawing.Bitmap; }
I have the below as my method:
And using razor to call this method for a string that I want shown as QR Code:
@vth.GenerateQR(item.name);
‘Bitmap’ does not contain a constructor that takes 1 arguments
Thank you :-)
THANKS ALOT FOX
VERYYYYY GOOOD !!
Great example. That I was looking for. But now I have some problems to show qrcode in my WPF window :/