小编给大家分享一下c#生成二维码的方法,希望大家阅读完这篇文章后大所收获,下面让我们一起去探讨吧!
引用ZXing类库
实现功能:
1生成带有Logo二维码
2 将二维码绘制到图片上
3 图片上绘制文字
生成二维码
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);
}
图片上生成文字
看完了这篇文章,相信你对c#生成二维码的方法有了一定的了解,想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。