ASP. NET generates a QR code, asp.net

Source: Internet
Author: User

ASP. NET generates a QR code, asp.net

The following uses the class library ThoughtWorks. QRCode. dll to generate a QR code.

 

Add the following three namespaces for use:

 

Using ThoughtWorks. QRCode. Codec;

Using ThoughtWorks. QRCode. Codec. Data;

Using ThoughtWorks. QRCode. Codec. Util;

 

The following code is mainly used in asp.net to generate a QR code image, which is displayed on the webpage and saved in D: \ zlf \ zz. Png;

 

C # code Replication
Using System; using System. configuration; using System. data; using System. linq; using System. web; using System. web. security; using System. web. UI; using System. web. UI. htmlControls; using System. web. UI. webControls; using System. web. UI. webControls. webParts; using System. xml. linq; using System. drawing. imaging; using ThoughtWorks. QRCode. codec; using ThoughtWorks. QRCode. codec. data; using ThoughtWorks. QRCode. codec. util; Using System. IO; using System. text; public partial class _ Default: System. web. UI. page {protected void Page_Load (object sender, EventArgs e) {} protected void button#click (object sender, EventArgs e) {response QRCodeEncoder = new qrCodeEncoder (); QRCodeEncoder. QRCodeEncodeMode = QRCodeEncoder. ENCODE_MODE.BYTE; qrCodeEncoder. QRCodeScale = 4; qrCodeEncoder. QRCodeVersion = 8; qrCodeEncoder. QR CodeErrorCorrect = QRCodeEncoder. ERROR_CORRECTION.M; // String data = "Hello QR code! "; String data = TextBox1.Text. toString (); 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); Response. clearContent (); Response. contentType = "image/Png"; Response. binaryWrite (MStream. toArray (); // FileInfo f = new FileInfo (@ "d: \ zl.png"); Director Y. CreateDirectory ("d :\\\ zlf"); FileStream fs = new FileStream ("d :\\\ zlf \\\\ zz. Png ", 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 ();}}

 

Aspx page code

HTML code Replication
<% @ Page Language = "C #" AutoEventWireup = "true" CodeFile = "Default. aspx. cs "Inherits =" _ Default "%> 

Aspnet (ThoughtWorksQRCodedll) QR code

Qre. QRCodeEncodeMode = QRCodeEncoder. ENCODE_MODE.BYTE; // For details

This indicates a encoding method.
Qre. QRCodeScale = 4; // detailed description
Qre. QRCodeVersion = 8; // detailed description
What are the version numbers and numbers. You can change the number. The size of the generated image will be different.
Qre. QRCodeErrorCorrect = QRCodeEncoder. ERROR_CORRECTION.H; // For details

This is the level of the Failover rate. . H. M or something. Controllable
You probably know what this means. Let me give you a detailed answer, and I am also powerless to use it after all. That's not to say we need to thoroughly study it.

How to generate a QR code aspnet

Reference
Qrcodenet.codeplex.com/
 

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.