Use Zxing one-dimensional code, zxing

Source: Internet
Author: User

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:

 

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.