Use C # to generate a two-dimensional code picture and save it to the specified directory.
1. Add a reference to the generated QR code picture DLL:
: Http://files.cnblogs.com/files/zflsyn/ThoughtWorks.QRCode.zip
2. Referencing namespaces
1 using System.Text; 2 using System.Drawing; 3 using ThoughtWorks; 4 using Thoughtworks.qrcode; 5 using ThoughtWorks.QRCode.Codec;
3. Add a method to create a two-dimensional code image
1 /// <summary>2 ///generate a QR code image and return the file's save path3 /// </summary>4 /// <param name= "nr" >a string to generate a two-dimensional code</param>5 /// <returns></returns>6 Private stringCREATEQR (stringnr)7 {8 Bitmap bt;9 if(!string. IsNullOrEmpty (NR))Ten { One stringfilename =Guid.NewGuid (). ToString (). ToUpper (); AQrcodeencoder Qrcodeencoder =NewQrcodeencoder (); -BT =Qrcodeencoder.encode (NR, Encoding.UTF8); - stringImgpath = Server.MapPath ("~/images/qrcodeimg/") + filename +". jpg"; the Try - { - BT. Save (Imgpath); - returnImgpath; + } - Catch(Exception) + { A return ""; at } - } - Else - { - return ""; - } in}
4. Use this method
string str = CREATEQR ("something");
C # Generate two-dimensional code images