C# tips and tricks 27 - How to generate and Read QR Code using ZXing.Net library in c#

Опубликовано: 04 Октябрь 2024
на канале: Ankpro Training
12,059
90

Generate and Read QR Code using ZXing.Net library in c#

What is QR Code?
QR Code - Quick Response Code

A QR Code is a two dimensional square barcode which can store encoded data.

Uses Of QR code :
Mobile payment applications to make transactions.
Business cards to allow people to save contact details.
Print advertisement to allow readers to visit the website, register for an event.
Product packaging to allow consumers to get more information.
Event or travel tickets to authorize and log entry.
Class material to engage and teach children.

List of Library for QR code:
ZXing.Net
Zxing.Net.Mobile
QRCoder
QrCodeNet
jquery-qrcode
Xam.Forms.QRCode
MessagingToolkit.QRCode
ZXing.Win.QRCode
Retyped.qrcode-generator
Gma.QrcodeNet

Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZXing;
using System.Drawing;

namespace QRCodeDemo
{
class Program
{
static void Main(string[] args)
{
//generate qr code
var qrcodeWriter = new BarcodeWriter();

qrcodeWriter.Format = BarcodeFormat.QR_CODE;

qrcodeWriter.Write("http://ankpro.com")
.Save(@"F:\qrcode\demo.bmp");
Console.WriteLine("Qr code is generated");

//read the qr code

var qrcodebitmap = (Bitmap)Bitmap.FromFile(@"F:\qrcode\demo.bmp");
var qrcodeReader = new BarcodeReader();
var qrcodeResult = qrcodeReader.Decode(qrcodebitmap);

Console.WriteLine($"Decode barcode text : {qrcodeResult.Text}");
Console.WriteLine($"barcode format: {qrcodeResult.BarcodeFormat}");
Console.WriteLine("Qr code read successfully");
}
}
}