C # generates two-dimensional code (QR code) using Qrcode.net

Source: Internet
Author: User

Many applications on the web are using QR codes to share URLs or other information. Especially in the mobile domain, the QR code is a very large application scenario. Because of the needs of the project, need to add a Web site to generate two-dimensional code analysis of the function of the URL, in the case of large cramps in Google's frustration using Baidu. Baidu N More, find some projects, but the availability is not strong. (There is a project developed with VS2005, debugging in 2010 does not open.) Finally found a "artifact" on the CodePlex, this "artifact" can be very convenient to generate two-dimensional code, speed that is quite fast, and can support Chinese, adhere to the MIT Protocol.

Qrcode.net is a class library written in C # to generate two-dimensional code images, which makes it easy to provide QR code output functionality for WinForm, WebForm, WPF, Silverlight, and Windows Phone 7 applications. You can export two-dimensional code files to EPS format.

The project address is: http://qrcodenet.codeplex.com

The qrcode.net no longer uses the http://code.google.com/p/zxing/ZXing port, and the new version will have better performance.

The test results are as follows (in microseconds):

Input string Length: 74 x

EC Performance tests~ qrcode.net:3929 zxing:5221

At the same time, Qrcode.net can parse the string and decide whether to use UTF-8 encoding. (for example, when using Chinese.) )

1.Graphics

        //const string str = "Hello world!";        Const stringstr ="http://www.weilanwu.com"; protected Override voidOnPaint (PaintEventArgs e) {Base.            OnPaint (e);        ShowCode (E.graphics); }        //draw the QR code on the graphics        Private voidShowCode (Graphics g) {Qrencoder Qrencoder=NewQrencoder (ErrorCorrectionLevel.H); QRCode QRCode=Qrencoder.encode (str); Fixedmodulesize modulesize=NewFixedmodulesize (2, Quietzonemodules.two); Graphicsrenderer Render=Newgraphicsrenderer (modulesize, Brushes.black, brushes.white); Render.        Draw (g, Qrcode.matrix); }

Show Results:

2. Generate to Picture

        /** Fixedmodulesize---5-----165*165 * Fixedmodulesize---4-----132*132 * Fixedmodulesize---3---- -99*99 * Fixedmodulesize---2-----66*66 * Fixedmodulesize---1-----33*33*/        //save QR Code directly to file        Private voidSavecodefile () {Qrencoder Qrencoder=NewQrencoder (ErrorCorrectionLevel.H); QRCode Code=NewQRCode (); Qrencoder.tryencode (str, outcode); Const intModelsizeinpixels =4; Graphicsrenderer Render=NewGraphicsrenderer (Newfixedmodulesize (Modelsizeinpixels, Quietzonemodules.two), Brushes.black, brushes.white); stringfilename = Localpathhelper.desktoppath +"/one.png"; using(FileStream stream =NewFileStream (filename, filemode.create)) {Render. WriteToStream (code.            Matrix, Imageformat.png, stream); }        }

Show Results:

C # generates two-dimensional code (QR code) using Qrcode.net

Related Article

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.