Generation of two-dimensional code code using QRCode in asp.net

Source: Internet
Author: User

1, use the following code first need to download QRCode.DLL file reference to your project

The code is as follows Copy Code

Generate two-dimensional Code code
public string Generateqrcode ()
{
Generate a two-dimensional code
string filename = string. Empty;
string filepath = string. Empty;

String TXT_QR = "need to generate two-dimensional code information";
String qrencoding = "Byte";
String level = "M";
String txt_ver = "7";
String txt_size = "4";

Qrcodeencoder Qrcodeencoder = new Qrcodeencoder ();
String encoding = qrencoding;
if (encoding = = "Byte")
{
Qrcodeencoder.qrcodeencodemode = Qrcodeencoder.encode_mode. BYTE;
}
else if (encoding = "alphanumeric")
{
Qrcodeencoder.qrcodeencodemode = Qrcodeencoder.encode_mode. Alpha_numeric;
}
else if (encoding = "Numeric")
{
Qrcodeencoder.qrcodeencodemode = Qrcodeencoder.encode_mode. NUMERIC;
}
Try
{
int scale = convert.toint16 (txt_size);
Qrcodeencoder.qrcodescale = scale;
}
catch (Exception ex)
{
Return "";
}
Try
{
int version = Convert.ToInt16 (Txt_ver);
Qrcodeencoder.qrcodeversion = version;
}
catch (Exception ex)
{
Return "";
}
string errorcorrect = level;
if (Errorcorrect = = "L")
Qrcodeencoder.qrcodeerrorcorrect = qrcodeencoder.error_correction. L
else if (Errorcorrect = = "M")
Qrcodeencoder.qrcodeerrorcorrect = qrcodeencoder.error_correction. M
else if (Errorcorrect = "Q")
Qrcodeencoder.qrcodeerrorcorrect = qrcodeencoder.error_correction. Q;
else if (Errorcorrect = = "H")
Qrcodeencoder.qrcodeerrorcorrect = qrcodeencoder.error_correction. H

Image Image;
String data = TXT_QR;
Image = Qrcodeencoder.encode (data);
filename = Guid.NewGuid (). ToString () + ". jpg";
filepath = "Two-dimensional code picture storage path" + filename;
System.IO.FileStream fs = new System.IO.FileStream (filepath, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
Image. Save (FS, System.Drawing.Imaging.ImageFormat.Jpeg);
Fs. Close ();
Image. Dispose ();
return filepath;
}

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.