. NET generates two-dimensional code

Source: Internet
Author: User

  1. To use a class: Qrcodeencoder

    This class to add a dynamic library: ThoughtWorks.QRCode.dll (I do not know how to upload attachments, readers can search the Internet, can also give the author message)

    Then introduce namespaces: using ThoughtWorks.QRCode.Codec;

  2. Well, the project begins.

    First, declare an instance of the Qrcodeencoder class:

    Qrcodeencoder Qrcodeencoder = new Qrcodeencoder ();

  3. Set the encoding method:

    Qrcodeencoder.qrcodeencodemode = Qrcodeencoder.encode_mode. BYTE;

    Here the author set it to byte-coding (there are two ways to encode, readers can test themselves), now the popular universal QR code is byte-coded.

  4.  

    set scale and version:

    < p>

    qrcodeencoder.qrcodeversion = 7;

    Here the size is: 4, Version: 7, the rest of the value of the reader can self-test, these two values basically only changed the size of the QR code, the reader set the value is now commonly used values.

  5.  

  6. Generate two-dimensional code based on the content of the image, and finally display the resulting image can be:

    String link = "Http://jingyan.baidu.com/user/npublic?un=%E8%BE%B9%E7%BC%98%E6%B2%B3%E5%9B%BE";

    BMP = Qrcodeencoder.encode (link);

    In general, the QR code generates a connection (of course, the reader can change to arbitrary text).

  7. The author here encapsulates it into a method that is easy to use:

    <summary>

    Get QR code based on link

    </summary>

    <param name= "link" > Links </param>

    <returns> return QR code image </returns>

    Private Bitmap Getdimensionalcode (string link)

    {

    Bitmap bmp = null;

    Try

    {

    Qrcodeencoder Qrcodeencoder = new Qrcodeencoder ();

    Qrcodeencoder.qrcodeencodemode = Qrcodeencoder.encode_mode. BYTE;

    Qrcodeencoder.qrcodescale = 4;

    int version = Convert.ToInt16 (Cboversion.text);

    Qrcodeencoder.qrcodeversion = 7;

    Qrcodeencoder.qrcodeerrorcorrect = qrcodeencoder.error_correction. M

    BMP = Qrcodeencoder.encode (link);

    }

    catch (Exception ex)

    {

    MessageBox.Show ("Invalid version!");

    }

    return BMP;

    }

  8. 8

    OK, take care, look at the two-dimensional code we generated, hehe!

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.