C # generate a QR code,

Source: Internet
Author: User

C # generate a QR code,

Reference ZXing class library

Functions:

1 generate a QR code with a Logo

2. Draw the QR code to the image.

3. Draw text on the Image

 

Generate QR code
1 public string CreateQrCode (string md5Str, string name, int sex) 2 {3 string str = sex = 1? "Sir": "Ms"; 4 string logoPath = AppDomain. currentDomain. baseDirectory + "/logo.png"; 5 string qrCodePath = path + DateTime. now. toString ("yyyyMMddHHmmss") + ". jpg "; 6 string yqPath = AppDomain. currentDomain. baseDirectory + "/yq2.jpg"; 7 string yqCardPath = path + TCommon. md5 (DateTime. now. toString ("yyyyMMddHHmmss") + ". jpg "; 8 if (Directory. exists (path) = false) // create the file folder 9 {10 Directory if it does not exist. createDirectory (path); 11} 12 Generate3 (md5Str, logoPath, qrCodePath); 13 Image qrCodeImg = new Bitmap (qrCodePath); 14 Image image = new Bitmap (yqPath ); 15 Graphics ig = Graphics. fromImage (image); 16 Font font = new Font ("Arial", 38, FontStyle. bold); 17 Font font2 = new Font ("STXINWEI", 38, FontStyle. bold); 18 Brush brush = System. drawing. brushes. black; 19 SizeF size = ig. measureString (name, font2); 20 SizeF size2 = ig. measureString (str, font); 21 ig. drawString (name, font, brush, (720-size.Width-size2.Width)/2,680); 22 ig. drawString (str, font, brush, (720-size. width-size2.Width)/2 + size. width, 680); 23 ig. fillRectangle (Brushes. white, 280,351,160,160); 24 ig. drawImage (qrCodeImg, 285,356); 25 image. save (yqCardPath); 26 return yqCardPath. substring (2); 27}
Generate text on the Image

 

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.