Use Zxing one-dimensional code, zxing
Recently, I was pleasantly surprised to see the QR code scanning on mantai Street. I also had some knowledge about the QR code. I wanted to see what the principle was. I found some information on the Internet and made an example for myself, MVC is used. Post it and share it with you.
One-dimensional code generation
Controller
public ActionResult QRCodView() { return View(); }
1 <div class = "col-md-4"> 2 // Generate public string Create () {string context = Request. Form ["context"]; string imgPath = CommCor. BarCodeUnit. CreateBarCode (context, Server. MapPath ("~ /TempFiled/"); return"/TempFiled/"+ imgPath ;}// Reference the namespace using ZXing; using System. drawing; using ZXing. qrCode; using ZXing. common; using System. text. regularExpressions; using System. drawing. imaging; using ZXing. qrCode. internal; using System. IO; /// <summary> /// one-dimensional code generation /// </summary> /// <param name = "contents"> </param> public static string CreateBarCode (string contents, string tempPath) {EncodingOptions options = null; BarcodeWriter writer = null; options = new EncodingOptions {Width = 200, Height = 200}; writer = new BarcodeWriter (); writer. format = BarcodeFormat. ITF; writer. options = options; Bitmap bitmap = writer. write (contents); string fileName = Guid. newGuid (). toString () + ". png "; bitmap. save (tempPath + fileName); return fileName ;}One-dimensional code generation core code
Results: