Example sharing of how to generate QR code in c#

黄舟
Release: 2017-09-19 11:19:00
Original
1953 people have browsed it

Quote ZXing class library

Implementation functions:

1 Generate QR code with Logo

2 Draw QR code onto picture

3 Draw text on the picture

Generate QR code

public string CreateQrCode(string md5Str,string name,int sex) { string str = sex == 1? "先生":"女士"; string logoPath = AppDomain.CurrentDomain.BaseDirectory + "/logo.png"; string qrCodePath = path + DateTime.Now.ToString("yyyyMMddHHmmss") + ".jpg"; string yqPath = AppDomain.CurrentDomain.BaseDirectory + "/yq2.jpg"; string yqCardPath = path + TCommon.Md5(DateTime.Now.ToString("yyyyMMddHHmmss")) + ".jpg"; if (Directory.Exists(path) == false)//如果不存在就创建file文件夹 { Directory.CreateDirectory(path); } Generate3(md5Str,logoPath,qrCodePath); Image qrCodeImg = new Bitmap(qrCodePath); Image image = new Bitmap(yqPath); Graphics ig = Graphics.FromImage(image); Font font = new Font("Arial", 38,FontStyle.Bold); Font font2 = new Font("STXINWEI", 38, FontStyle.Bold); Brush brush = System.Drawing.Brushes.Black; SizeF size = ig.MeasureString(name, font2); SizeF size2 = ig.MeasureString(str, font); ig.DrawString(name, font, brush, (720-size.Width-size2.Width) /2, 680); ig.DrawString(str, font, brush, (720 - size.Width - size2.Width) / 2 + size.Width, 680); ig.FillRectangle(Brushes.White, 280, 351, 160, 160); ig.DrawImage(qrCodeImg, 285, 356); image.Save(yqCardPath); return yqCardPath.Substring(2); } 图片上生成文字
Copy after login

The above is the detailed content of Example sharing of how to generate QR code in c#. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!