C # Generate two-dimensional code images

Source: Internet
Author: User

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

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.