Sharing asp.net two-dimensional codes using Thoughtworks.qrcode and Qrcode.net

Source: Internet
Author: User

Recently doing projects encountered the problem of generating two-dimensional code, found that the most used online is thoughtworks.qrcode and qrcode.net two ways. Visit the official website to see Example wrote two demo, using the process found that two are pretty good, thoughtworks.qrcode function more, but the DLL file has 6 trillion, qrcode.net only more than 400 K, we need to choose according to their own. The attached code is for reference only.

Thoughtworks.qrcode:

The code is as follows Copy Code
private void Createqrcode (string nr)
{
Bitmap BT;
String encodestring = nr;
Qrcodeencoder Qrcodeencoder = new Qrcodeencoder ();
BT = Qrcodeencoder.encode (encodestring, Encoding.UTF8);
string filename = DateTime.Now.ToString ("Yyyymmddhhmmss");
String path = Server.MapPath ("~/image/") + filename + ". jpg";
Response.Write (path);
Bt. Save (path);
This. Image1.imageurl = "~/image/" + filename + ". jpg";
}



qrcode.net:

The code is as follows Copy Code
protected void Button1_Click (object sender, EventArgs e)
{
using (var ms = new MemoryStream ())
{
String stringtest = "China inghttp://www.baidu.com/mvc.test?&";
Getqrcode (Stringtest, MS);
Response.ContentType = "Image/png";
Response.OutputStream.Write (Ms. GetBuffer (), 0, (int) Ms. Length);


Image img = image.fromstream (ms);
string filename = DateTime.Now.ToString ("Yyyymmddhhmmss");
String path = Server.MapPath ("~/image/") + filename + ". png";
Img. Save (path);


Response.End ();
}


}


<summary>
Get two dimensional code
</summary>
<param name= "Strcontent" > characters to be encoded </param>
<param name= "MS" > Output Flow </param>
<returns>true if the encoding succeeded, false if the content is empty or too large to fit in a QR Code</retur Ns>
public static bool Getqrcode (string strcontent, MemoryStream ms)
{
Errorcorrectionlevel Ecl = errorcorrectionlevel.m; Error correction level
String content = strcontent;//content to be encoded
Quietzonemodules quietzones = quietzonemodules.two; Blank area
int modulesize = 12;//size
var encoder = new Qrencoder (ECL);
QRCode QR;
if (encoder. Tryencode (content, out QR))//encode the contents and save the generated matrix
{
var render = new Graphicsrenderer (new Fixedmodulesize (Modulesize, quietzones));
Render. WriteToStream (QR. Matrix, Imageformat.png, MS);
}
Else
{
return false;
}
return true;
}

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.