-
To use a class: Qrcodeencoder
This class to add a dynamic library: ThoughtWorks.QRCode.dll (I do not know how to upload attachments, readers can search the Internet, can also give the author message)
Then introduce namespaces: using ThoughtWorks.QRCode.Codec;
-
Well, the project begins.
First, declare an instance of the Qrcodeencoder class:
Qrcodeencoder Qrcodeencoder = new Qrcodeencoder ();
-
Set the encoding method:
Qrcodeencoder.qrcodeencodemode = Qrcodeencoder.encode_mode. BYTE;
Here the author set it to byte-coding (there are two ways to encode, readers can test themselves), now the popular universal QR code is byte-coded.
-
set scale and version:
< p>
qrcodeencoder.qrcodeversion = 7;
Here the size is: 4, Version: 7, the rest of the value of the reader can self-test, these two values basically only changed the size of the QR code, the reader set the value is now commonly used values.
-
-
Generate two-dimensional code based on the content of the image, and finally display the resulting image can be:
String link = "Http://jingyan.baidu.com/user/npublic?un=%E8%BE%B9%E7%BC%98%E6%B2%B3%E5%9B%BE";
BMP = Qrcodeencoder.encode (link);
In general, the QR code generates a connection (of course, the reader can change to arbitrary text).
-
The author here encapsulates it into a method that is easy to use:
<summary>
Get QR code based on link
</summary>
<param name= "link" > Links </param>
<returns> return QR code image </returns>
Private Bitmap Getdimensionalcode (string link)
{
Bitmap bmp = null;
Try
{
Qrcodeencoder Qrcodeencoder = new Qrcodeencoder ();
Qrcodeencoder.qrcodeencodemode = Qrcodeencoder.encode_mode. BYTE;
Qrcodeencoder.qrcodescale = 4;
int version = Convert.ToInt16 (Cboversion.text);
Qrcodeencoder.qrcodeversion = 7;
Qrcodeencoder.qrcodeerrorcorrect = qrcodeencoder.error_correction. M
BMP = Qrcodeencoder.encode (link);
}
catch (Exception ex)
{
MessageBox.Show ("Invalid version!");
}
return BMP;
}
- 8
OK, take care, look at the two-dimensional code we generated, hehe!