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