C # generates two-dimensional code

Source: Internet
Author: User

Directly referencing the ThoughtWorks.QRCode.dll class in C #,

Qrcodeencoder Qrcodeencoder = new Qrcodeencoder ();
Qrcodeencoder.qrcodeencodemode = Qrcodeencoder.encode_mode.    BYTE; Encoding method (Note: Byte can support Chinese, alpha_numeric scan out is the number)
Qrcodeencoder.qrcodescale = 4; Size (the larger the value, the higher the image pixel of the resulting QR code)
Qrcodeencoder.qrcodeversion = 8; Version (note: setting to 0 is primarily to prevent an error when the encoded string is too long)
Qrcodeencoder.qrcodeerrorcorrect = qrcodeencoder.error_correction.       M Error validation, error correction (4 levels)
String data = "http://www.xxxxx.com/register.aspx?refpeople=" + username + ""; Two-dimensional code information
Context. Response.Write (data);
System.Drawing.Bitmap image = Qrcodeencoder.encode (data);
System.IO.MemoryStream mstream = new System.IO.MemoryStream ();
Image. Save (Mstream, System.Drawing.Imaging.ImageFormat.Png);
Context. Response.clearcontent ();
Context. Response.ContentType = "Image/png";
Context. Response.BinaryWrite (Mstream.toarray ());
String path = context. Server.MapPath ("~/uploadfile/twocode");

Directory.CreateDirectory (path);
Path = path + "\ \" + DateTime.Now.ToString ("YYYYMMDDHHMMSS") + ". png";
FileStream fs = new FileStream (path, filemode.createnew, FileAccess.ReadWrite);
BinaryWriter bw = new BinaryWriter (FS, Utf8encoding.utf8);
byte[] by = Mstream.toarray ();
for (int i = 0; i < Mstream.toarray (). Length; i++)
Bw. Write (By[i]);
Fs. Close ();

String relativepath = "/uploadfile/twocode/" + DateTime.Now.ToString ("YYYYMMDDHHMMSS") + ". png";

C # generates two-dimensional code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.