Asp. NET to write Web pages in C # language and generate two-dimensional code for the text you enter.
Tools/Materials
1. New
- 1
Create a new project (new project),
- 2
Select Visual C #---->asp.net Web application and click OK.
- 3
Right-click New Item,
- 4
Select Web Form (Webform),
- 5
Create a new folder image, which you want to use later.
END
2, the basic layout of the page
- 1
In the newly created WEBFORM1, switch to Design view, add TextBox Control and button control, change the button control's Text property (surface text) to "generate two-dimensional code", (Do not change, here for the sake of beautiful change).
- 2
Add an image control, make the picture larger, or change the width and height properties of the image control, adjust the position of the control (or not, and adjust it slightly for aesthetics).
END
3. Download the DLL file and reference
- 1
Download ThoughtWorks.QRCode.dll to the desktop (other paths can also, as long as you know on the line), do not worry, the file is very small. This is the DLL file that generates the QR code. If it's less, it won't work.
- 2
When the download is complete, add a reference (add Reference),
- 3
Select the ThoughtWorks.QRCode.dll file that you just downloaded, add it in,
- 4
In this step you can see the DLL files that have been added.
END
4. Backstage Code
- 1
Double-click the Generate two-dimensional code button to enter the background code, first add the namespace:
Using System.Text;
Using ThoughtWorks;
Using Thoughtworks.qrcode;
Using ThoughtWorks.QRCode.Codec;
Using ThoughtWorks.QRCode.Codec.Data;
Using System.Drawing;
,
- 2
To invoke a method in a button click event:
Create_two (this. TextBox1.Text);
Add a method (note the location of the method):
private void Create_two (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";
}
END
5. Compiling and browsing
- 1
Compilation (Rebuild),
- 2
View in the browser,
- 3
Enter the text you want, such as "OK" and click Generate QR code. Effect
END
6. File Save
Files are automatically saved to the local Project image folder after successful browsing
You can also view it in the VS editor, notice that you want to show all the files to see, click "Show All" to display the file
END
Precautions.
measured at present only by the use of the browser "sweep" scan it, and other still can not be achieved, such as the reader can be achieved, hope to enlighten!
Here VS2010 Chinese version for example, corresponding to the other version and English are the same, careful on the line.
To first compile and then browse
Asp. NET C # generates two-dimensional code