[C #] Two-dimensional code (QR code) generation and parsing

Source: Internet
Author: User

Write in front

Often in the street to hear what the sweep code to send, if really idle all right, from scratch in place, estimated schoolbag are filled with all kinds of things. All kinds of sweeping to send, too flooded. The project has never touched the two-dimensional code of East, recently to use, grilled the network, found about the resolution of the two-dimensional code of the class library is still very much, here choose one to do a demo, play.

An example

There are still a lot of components about QR codes, you can use NuGet to choose one.

Generate two-dimensional code

        //Get:home         PublicActionResult Index () {Qrcodeencoder Endocder=NewQrcodeencoder (); //Two-dimensional code background colorEndocder. Qrcodebackgroundcolor =System.Drawing.Color.White; //Two-dimensional code encoding methodEndocder. Qrcodeencodemode =Qrcodeencoder.encode_mode.            BYTE; //the width of each small squareEndocder. Qrcodescale =Ten; //Two-dimensional code version numberEndocder. Qrcodeversion =5; //Error Correction levelEndocder. Qrcodeerrorcorrect =qrcodeencoder.error_correction.            M varperson =New{Id =1, Name ="Wolfy", Gender =1, age = - }; //make a two-dimensional code of the JSON ChuanBitmap Bitmap = Endocder. Encode (NewJavaScriptSerializer ().            Serialize (person), System.Text.Encoding.UTF8); stringStrsavedir = Request.mappath ("/qrcode/"); if(!directory.exists (Strsavedir))            {directory.createdirectory (Strsavedir); }            stringStrsavepath = Path.Combine (Strsavedir, person. Name +". PNG"); if(!System.IO.File.Exists (Strsavepath)) {Bitmap.            Save (Strsavepath); } viewbag.img="/qrcode/"+ person. Name +". PNG"; returnView (); }

Browse

How to parse it?

         Public stringDeCoder () {stringresult =""; stringStrsavedir = Request.mappath ("/qrcode/"); if(!directory.exists (Strsavedir))            {directory.createdirectory (Strsavedir); }            stringStrsavepath = Path.Combine (Strsavedir,"Wolfy.png"); if(System.IO.File.Exists (Strsavepath)) {Qrcodedecoder decoder=NewQrcodedecoder (); Result= Decoder.decode (NewThoughtWorks.QRCode.Codec.Data.QRCodeBitmapImage (NewBitmap (Image.FromFile (Strsavepath))); }            returnresult; }

Parsing results

Scan results

Summarize

Here is just a demo to play. QR code is useful, such as scan login, scan payment, scan and download app ... On the street sweep the code, from this head sweep to that head, can sweep a pile of things. This is also the sweep of goods ...

[C #] Two-dimensional code (QR code) generation and parsing

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.