c#如何生成二维码的示例分享

发布时间:2022-05-16 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了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#如何生成二维码的示例分享的详细内容,更多请关注脚本宝典其它相关文章

脚本宝典总结

以上是脚本宝典为你收集整理的c#如何生成二维码的示例分享全部内容,希望文章能够帮你解决c#如何生成二维码的示例分享所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。