C # Generate two-dimensional code business cards

Source: Internet
Author: User
Tags vcard

From the "31-Day Learning CRM Project Development <c# programming entry-level project combat >"

This example uses the Thoughtworks.qrcode class library to generate a two-dimensional code card. Before formally coding, what is a vCard first ? It is a standard or specification used to define an electronic business card. Mobile phone records can be exported in vCard format. Fragment 21-15 is a vCard format text, from the data structure is not complex, according to the format to fill the relevant information, in two-dimensional code output.

    Begin:vcard      FN: Zhang San      TITLE: Technical director      ORG: Qingdao * * Software Co., Ltd.; ERP Business Department      TEL; cell:18605327777      TEL; work:+86 0532 86887777      TEL; work; 传真: 0532 86887778      ADR; Work: Qingdao South District, Hong Kong Road, No. 100th      URL:www.huiyaosoft.com      EMAIL; Work:[email protected]      Note:      x-qq:      PHOTO; Encoding=b; Type=jpeg:      End:vcard  

The main development steps are as follows:

(1) Draw form 21-7 as shown

(2) Add Reference ThoughtWorks.QRCode.dll
(3) Fragment 21-16 use Thoughtworks.qrcode to export business card information to PictureBox1, the more information, the larger the two-dimensional code image. If the picture is small, the information is relatively large, the generated QR code is not easy to identify. Line 31-34 demonstrates the way to add a logo to a QR code image, because the QR code itself has a certain ability to correct the error.
Code Snippet 21-16

     Public StaticBitmap Gettwodimensioncode (stringstrsource,stringTextintWidthintHeightstringfontname) {          //Create a Bitmap objectBitmap BMP =NewBitmap (width, height); //Create a Graphics object from imageGraphics Objgraphics =graphics.fromimage (BMP); //fill in the background colorObjgraphics.fillrectangle (Brushes.white,0,0, BMP. Width, BMP.          Height); //ThoughtWorks.QRCode.Codec.QRCodeEncoder Qrcodeencoder =NewThoughtWorks.QRCode.Codec.QRCodeEncoder (); //Setting the Encoding methodQrcodeencoder.qrcodeencodemode =ThoughtWorks.QRCode.Codec.QRCodeEncoder.ENCODE_MODE.          BYTE; //Set SizeQrcodeencoder.qrcodescale =3; //for less informative situations, the smaller the image, the less information is saved//Qrcodeencoder.qrcodescale = 4; //Set VersionQrcodeencoder.qrcodeversion =0; //set the level of error check, just because the QR code has the ability to correct, to join the logoQrcodeencoder.qrcodeerrorcorrect =ThoughtWorks.QRCode.Codec.QRCodeEncoder.ERROR_CORRECTION.          M Image Image= Qrcodeencoder.encode (strsource, Encoding.GetEncoding ("Utf-8")); //write QR code        intx = (int) (Width-image. Width)/2; inty = (int) (Height-image. Height)/2; Objgraphics.drawimage (Image,NewPoint (x, y)); //Add logo iconImage =TwoDimensionCodeNameCard.Properties.Resources.Apps_tux_icon; X= (int) (Width-image. Width)/2; Y= (int) (Height-image. Height)/2; Objgraphics.drawimage (Image,NewPoint (x, y)); returnbmp; }  

In code snippet 21-16, line 34 uses the DrawImage () method to add an image to the Objgraphics specified location, and code snippet 21-17 demonstrates the use of the drawstring () The Objgraphics method adds the string text to the specified position.

Code Snippet 21-17

    // Write String      New  - , FontStyle.Bold),           new PointF ();  

Sample Download: http://download.csdn.net/detail/daiqianjie/9472868

C # Generate two-dimensional code business cards

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.