How to Generate QR Code in C#

Generate QR Code in C#

  1. I am using a third party dll named as Zxing. It’s Originally developed in java platform.

  2. We can specify the Height and Width of generated QR image.

  3. I have attached the dll for you to download.

  4. We can also generate other codes such as MAXICODE,UCP and so on.

 

  1. private void Form1_Load(object sender, EventArgse)   
  2. {  
  3.    Bitmap img = GenerateQR(50, 50, "Becauset he DataContext class is the entry point to the LINQ-to-SQL data model");  
  4.    img.Save(@"D:\TESTING FROM APPS c#/hari.bmp");// Give the path to save the generated bitmap image  
  5. }  
  6. public Bitmap GenerateQR(int width, int height, stringtext)  
  7. {  
  8.    var bw = new ZXing.BarcodeWriter();  
  9.    var encOptions = new Xing.Common.EncodingOptions() { Width= width, Height = height, Margin = 0 };  
  10.    bw.Options= encOptions;  
  11.    bw.Format =ZXing.BarcodeFormat.QR_CODE;  
  12.    var result = new Bitmap(bw.Write(text));  
  13.   
  14.    return result;  
  15. }