C # uses the ZXing.dll library to generate two-dimensional code

Source: Internet
Author: User

Recently work needs a need, that is, a service address to generate two-dimensional code, can be used to scan code sharing, online find the next method is more, I here PO call ZXing.dll Library to generate two-dimensional code method it. First, a brief introduction to the Zxing Library, Zxing Library is an open source Java class Library, can be used to generate and parse a variety of formats 1d/2d barcode;zxing follow Apache License 2.0, just tools, is no charge.

Zxing Library:http://zxingnet.codeplex.com/

Click to download , unzip the zip package after downloading:

Add the zxing to the engineering application, the following is the core code:

1 /// <summary>2         ///generate two-dimensional code images3         /// </summary>4         /// <param name= "strmessage" >a string to generate a two-dimensional code</param>5         /// <param name= "width" >Two-dimensional code image width</param>6         /// <param name= "height" >Two-dimensional code image height</param>7         /// <returns></returns>8         PrivateBitmap getqrcodebyzxingnet (String strmessage,int32 width,int32 height)9         {TenBitmap result =NULL; One             Try A             { -Barcodewriter Barcodewriter =NewBarcodewriter (); -Barcodewriter.format =Barcodeformat.qr_code; theBARCODEWRITER.OPTIONS.HINTS.ADD (Encodehinttype.character_set,"UTF-8"); - barCodeWriter.Options.Hints.Add (encodehinttype.error_correction, ZXing.QrCode.Internal.ErrorCorrection Level.H); -BarCodeWriter.Options.Height =height; -BarCodeWriter.Options.Width =width; +BarCodeWriter.Options.Margin =0; -ZXing.Common.BitMatrix BM =Barcodewriter.encode (strmessage); +result =Barcodewriter.write (BM); A             } at             Catch(Exception ex) -             {  -                 //Abnormal output -             } -             returnresult; -}

Look at the effect of creating a QR code:

At the same time, Zxing Library also supports the decoding of QR code images.

The core code for decoding is as follows:

/// <summary>        ///decode QR Code/// </summary>        /// <param name= "Barcodebitmap" >QR code image to decode</param>        /// <returns>Sweep Code Results</returns>        Private stringDecodeqrcode (Bitmap barcodebitmap) {Barcodereader reader=NewBarcodereader (); Reader. Options.characterset="UTF-8"; varresult =Reader.             Decode (BARCODEBITMAP); return(Result = =NULL) ?NULL: Result.        Text; }

Look at the effect:

Just looking for a QR code:

The sweep code results are as follows:

C # uses the ZXing.dll library to generate two-dimensional code

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.