A simple way to generate QRCode

Posted by Godsky under C# on 12/23/2012 | Points: 10 | Views : 4834 | Status : [Member] | Replies : 5
Before starting the programing, download the SDK/NET frm aipsys.com

1. Contants:

1.1. encoding scheme

public static int ENC_ALPHA = 0;
public static int ENC_BYTE = 1;
public static int ENC_NUMERIC = 2;
public static int ENC_KANJI = 3;
public static int ENC_AUTO = 4;

1.2. Version
1~40

1.3. FNC1Mode
public static int FNC1_MODE_NO = 0;
public static int FNC1_MODE_FIRST = 1;
public static int FNC1_MODE_SECOND = 2;

1.4. Correction Level

public static int CORRECTION_LEVEL_L = 0;
public static int CORRECTION_LEVEL_M = 1;
public static int CORRECTION_LEVEL_Q = 2;
public static int CORRECTION_LEVEL_H = 3;

2. Class discription

public ImageEncoder()
public bool RegisterQRCodeEncoder(string strMail, string strRegCode)
public System.Drawing.Bitmap Encode2Image()
public bool Encode2ImageFile(string filename)
public byte ApplicationIndicator { set; get; }
public bool AutoConfigurate { set; get; }
public System.Drawing.Color BackGroundColor { set; get; }
public int ECI { set; get; }
public int Encoding { set; get; }
public int ErrorCorrectionLevel { set; get; }
public int Fnc1Mode { set; get; }
public System.Drawing.Color ForeGroundColor { set; get; }
public int MarginSize { set; get; }
public int ModuleSize { set; get; }
public bool ProcessTilde { set; get; }
public bool StructuredAppend { set; get; }
public int StructuredAppendCounter { set; get; }
public int StructuredAppendIndex { set; get; }
public string TextData { set; get; }
public int Version { set; get; }

3. Samples
3.1 Encode to Bitmap
ImageEncoder iee = new ImageEncoder();
iee.AutoConfigurate = true;
iee.ECI = -1;
iee.Encoding = ImageEncoder.ENC_AUTO;
iee.Fnc1Mode = ImageEncode.FNC1_MODE_NO;
iee.ErrorCorrectionLevel = ImageEncoder.CORRECTION_LEVEL_L;
iee.Version = 1;
iee.ProcessTilde = false;
iee.MarginSize = 10;
iee.ModuleSize = 4;
iee.StructuredAppend = false;
iee.StructuredAppendCounter = 0;
iee.StructuredAppendIndex = 0;
iee.TextData = "http://www.aipsys.com";
pictureBox1.Image = iee.Encode2Image();

3.2 Encode to file
ImageEncoder iee = new ImageEncoder();
iee.AutoConfigurate = true;
iee.ECI = -1;
iee.Encoding = ImageEncoder.ENC_AUTO;
iee.Fnc1Mode = ImageEncode.FNC1_MODE_NO;
iee.ErrorCorrectionLevel = ImageEncoder.CORRECTION_LEVEL_L;
iee.Version = 1;
iee.ProcessTilde = false;
iee.MarginSize = 10;
iee.ModuleSize = 4;
iee.StructuredAppend = false;
iee.StructuredAppendCounter = 0;
iee.StructuredAppendIndex = 0;
iee.TextData = "http://www.aipsys.com";
iee.Encode2ImageFile("c:\\qrtest.png");




Responses

Posted by: Sdfwes on: 1/31/2013 [Member] Starter | Points: 25

Up
0
Down
Here is another useful source code for generating QR Code barcode in C# (http://www.onbarcode.com/tutorial/csharp-barcode-generation.html ) :
QRCode qrCode = new QRCode(); // Create QRCode object
qrCode.Data = "VB.NET QRCode"; // Set QR Code data to encode
qrCode.DataMode = QRCodeDataMode.Auto; // Set QRCode data mode (QR-Code Barcode Settings)
// Draw & print generated QR Code to jpeg image file
qrCode.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
qrCode.drawBarcode("C://csharp-qrcode.jpg");


Godsky, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Mariah on: 9/2/2013 [Member] Starter | Points: 25

Up
0
Down
what a surprise with so many big resource above! i thought i was so great to find the solution to how to generate qr code in C# by following this http://www.keepautomation.com/csharp_barcode/qrcode.html

Godsky, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Makaveiljojo on: 12/31/2013 [Member] Starter | Points: 25

Up
0
Down
I agree with Mariah. It's good source. I'm using another generator from that side to generate QR code and it work flawless.http://www.keepautomation.com/vbnet_barcode/qrcode.html

Godsky, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Susannamoore53 on: 3/25/2014 [Member] Starter | Points: 25

Up
0
Down
Thank you, great collection.
I also found a very useful barcode creator and it’s totally free to test:
http://www.rasteredge.com/how-to/winforms-net-imaging/barcode-generating/



Godsky, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Thomas128 on: 4/3/2014 [Member] Starter | Points: 25

Up
0
Down
Thanks for sharing this cool QR Code Creating example! I also found another barcode generator which also supports printing QR Code. I'm testing the trial version, and it offers very flexible settings to adjust my QR Code, like module size, barcode width & height, color, margins on four sides, etc. The samle's in VB.NET, so you might wanna convert to C# first if necessary.

http://www.yiigo.com/guides/vbnet/how-to-generate-qr-code.shtml


Dim doc As YGDocument = YGFile.OpenDocumentFile("c:/demo.pdf", New PDFReader())


Dim ygPage As YGPage = DirectCast(doc.GetPage(0), YGPage)

Dim qrcode As New QRCode()
qrcode.Data = "yourdata"

Dim ygBarcode As YGImage = qrcode.ToImage()

Dim obj As New EmbeddedImageAnnotation()
obj.FillImage = ygBarcode.ToBitmap(ygBarcode.GetWidth(), ygBarcode.GetHeight())

Dim item As Yiigo.Imaging.Drawing.YGItemEx = obj.CreateAnnotationItem(ygPage)
ygPage.MergeItemsToPage()
YGFile.SaveDocumentFile(doc, "c:/qrcode.pdf", New PDFCreator))


Today is a gift. That's why it's called the Present!

Godsky, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response