Two-dimensional code generation and decoding

Source: Internet
Author: User

There are three ways of doing this:

1, Zxing.net

Example Source:

        protected voidPage_Load (Objectsender, EventArgs e) {DateTime Dtbegin=DateTime.Now; stringFileName = AppDomain.CurrentDomain.BaseDirectory +"bin\\"+ Guid.NewGuid (). ToString () +". jpg"; stringContent = Httputility.urldecode ( This. request["content"]); Barcodewriter writer=NewBarcodewriter () {Format=Barcodeformat.qr_code, Options=Newencodingoptions () {Width= -, Height= -}, Renderer= (ibarcoderenderer<bitmap>) activator.createinstance (typeof(Bitmaprenderer))}; Bitmap BMP=writer.            Write (content); Bmp.            Save (FileName);  This.            Response.WriteFile (FileName); stringTime = (DateTime.Now-dtbegin).        Totalmilliseconds.tostring (); }
View Code

2, Qrcode.net

Example Source:

        protected voidPage_Load (Objectsender, EventArgs e) {DateTime Dtbegin=DateTime.Now; stringFileName = AppDomain.CurrentDomain.BaseDirectory +"bin\\"+ Guid.NewGuid (). ToString () +". jpg"; stringContent = Httputility.urldecode (request.querystring["content"]); Qrencoder Qrencoder=NewQrencoder (ERRORCORRECTIONLEVEL.M); QRCode QRCode=Qrencoder.encode (content); Graphicsrenderer renderer=NewGraphicsrenderer (NewFixedmodulesize (5, Quietzonemodules.two), Brushes.black, brushes.white); using(FileStream stream =NewFileStream (FileName, FileMode.Create)) {renderer.            WriteToStream (Qrcode.matrix, Imageformat.png, stream); }             This.            Response.WriteFile (FileName); stringSpendtime = (DateTime.Now-dtbegin).        Totalmilliseconds.tostring (); }
View Code

3, Thoughtworks.qrcode

Example Source:

        protected voidPage_Load (Objectsender, EventArgs e) {DateTime Dtbegin=DateTime.Now; stringContent = Httputility.urldecode (request.querystring["content"]); Bitmap Bitmap=Createqrcode (content); stringFileName = AppDomain.CurrentDomain.BaseDirectory +"bin\\"+ Guid.NewGuid (). ToString () +". jpg"; Bitmap.                        Save (FileName, imageformat.jpeg); Response.WriteFile (FileName,true); stringSpendtime = (DateTime.Now-dtbegin).        Totalmilliseconds.tostring (); }         PublicBitmap Createqrcode (stringcontent) {Qrcodeencoder Qrencoder=NewQrcodeencoder (); Qrencoder.qrcodeencodemode=Qrcodeencoder.encode_mode.            BYTE; Qrencoder.qrcodescale=4;//Convert.ToInt32 (txtsize.text);Qrencoder.qrcodeversion =7;//Convert.ToInt32 (cboversion.selectedvalue);Qrencoder.qrcodeerrorcorrect =qrcodeencoder.error_correction.            M Try{Bitmap QRCode=Qrencoder.encode (content, Encoding.UTF8); returnQRCode; }            Catch(IndexOutOfRangeException ex) {//exceeding the capacity limit of the current QR code version, please select a higher QR code version                return NewBitmap ( -, -); }            Catch(Exception ex) {//error generating QR code                return NewBitmap ( -, -); }        }
View Code

Precautions:

1. One way to request QR code on the Web is to assign the service page generating the QR code to the SRC attribute of .

2, three ways are open source projects, the use of the official website to download the source code, and add to the project can be

3, three way comparison: 3 processing speed is the fastest, in the web-side access processing time is probably 20ms,1 and 2 speed of not much, 50ms to 70ms or so, but 1 and 2dll smaller, hundreds of K, and 3 is 6M

4, Mode 3 of the demo run a problem, cause unknown origin

Two-dimensional code generation and decoding

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.