C # zxing.net generates two-dimensional code, identifies two-dimensional code, and generates a two-dimensional code with a logo (ii)

Source: Internet
Author: User

1. Use zxint.net to generate a QR code with logo

/// <summary>///Create a QR code with logo/// </summary>/// <param name= "text" ></param>Static voidGenerate3 (stringtext) {    //Logo ImageBitmap logo =NewBitmap (@"h:\ Desktop \\102.jpg"); //construction of two-dimensional code write code deviceMultiformatwriter writer =NewMultiformatwriter (); Dictionary<encodehinttype,Object> hint =NewDictionary<encodehinttype,Object>(); Hint. ADD (Encodehinttype.character_set,"UTF-8"); Hint.    ADD (encodehinttype.error_correction,errorcorrectionlevel.h); //generate two-dimensional codeBitmatrix BM = Writer.encode (Text,barcodeformat.qr_code, -, -, hint); Barcodewriter Barcodewriter=NewBarcodewriter (); Bitmap Map=Barcodewriter.write (BM); //get the actual size of the QR code (remove the actual size after the two-dimensional code is blank)    int[] Rectangle =Bm.getenclosingrectangle (); //calculate the size and position of the inserted picture    intMiddlew = Math.min ((int) (rectangle[2] /3.5), logo.    Width); intMiddleh = Math.min ((int) (rectangle[3]/3.5), logo.    Height); intMiddlel = (map. Width-middlew)/2; intMiddlet = (map. Height-middleh)/2; //convert img to BMP format, otherwise the graphics object cannot be created laterBitmap bmpimg =NewBitmap (map. Width,map.    HEIGHT,PIXELFORMAT.FORMAT32BPPARGB); using(Graphics g=graphics.fromimage (bmpimg)) {G.interpolationmode=System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; G.smoothingmode=System.Drawing.Drawing2D.SmoothingMode.HighQuality; G.compositingquality=System.Drawing.Drawing2D.CompositingQuality.HighQuality; G.drawimage (Map,0,0); }    //Insert the QR code into the pictureGraphics mygraphic =graphics.fromimage (BMPIMG); //White backgroundMygraphic.fillrectangle (Brushes.white,middlel,middlet,middlew,middleh);    Mygraphic.drawimage (Logo,middlel,middlet,middlew,middleh); //Save as PictureBmpimg. Save (@"h:\ Desktop \\generate3.png", imageformat.png);}

Call:

// Create a QR code with a picture Generate3 ("https://www.baidu.com/"); Generate3 ("Ionic is a powerful hybrid/hybrid HTML5 Mobile development Framework characterized by the use of standard HTML, CSS, and JavaScript to develop cross-platform applications, Just a few steps to quickly create your Ionic app and create an app from here ");

C # zxing.net generates two-dimensional code, identifies two-dimensional code, and generates a two-dimensional code with a logo (ii)

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.