Two-dimensional code (QR code) generation and parsing written 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 public ActionResult Index () {Qrcodeencoder endocder = new Qrcodeencoder (); Two-dimensional code background color endocder. Qrcodebackgroundcolor = System.Drawing.Color.White; Two-dimensional code encoding method Endocder. Qrcodeencodemode = Qrcodeencoder.encode_mode. BYTE; The width of each small square endocder. Qrcodescale = 10; Two-dimensional code version number Endocder. Qrcodeversion = 5; Error correction level Endocder. Qrcodeerrorcorrect = qrcodeencoder.error_correction. M var person = new {Id = 1, Name = ' Wolfy ', Gender = 1, age = 24}; The JSON Chuan is made into two-dimensional code Bitmap Bitmap = Endocder. Encode (New JavaScriptSerializer (). Serialize (person), System.Text.Encoding.UTF8); String strsavedir = Request.mappath ("/qrcode/"); if (! Directory.Exists (Strsavedir)) {directory.createdirectory (strsavedir); } String strsavepath = Path.Combine (Strsavedir, person. Name + ". PNG "); if (! System.IO.File.Exists (Strsavepath)) {bitmap. Save (Strsavepath); } viewbag.img = "/qrcode/" + person. Name + ". png"; return View (); }
Browse
How to parse it?
public string DeCoder () { string result = ""; String strsavedir = Request.mappath ("/qrcode/"); if (! Directory.Exists (Strsavedir)) { directory.createdirectory (strsavedir); } String strsavepath = Path.Combine (Strsavedir, "wolfy.png"); if (System.IO.File.Exists (Strsavepath)) { Qrcodedecoder decoder = new Qrcodedecoder (); result = Decoder.decode (new ThoughtWorks.QRCode.Codec.Data.QRCodeBitmapImage (New Bitmap (Image.FromFile (Strsavepath )))); } return result; }
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 ...
Two-dimensional code (QR code) generation and parsing