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


本文摘自PHP中文网,作者黄舟,侵删。

引用ZXing类库

实现功能:

1生成带有Logo二维码

2 将二维码绘制到图片上

3 图片上绘制文字

生成二维码

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

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#中关于minutes与totalminutes的区别

.net中关于接口和类之间的区别介绍

.net winform的gdi双缓冲的实现方法_实用技巧

.net core对mongodb执行多条件查询

.net framework有什么用

c#如何通过对象属性名修改值的实例

.net安装framework出现报错的处理教程

c#中sql参数传入空值出错误和如何解决办法

如何使用c#自定义音乐播放器进度条的实例分析

c#开发微信门户及应用(二)之微信消息处理和应答的图文代码教程

更多相关阅读请进入《csharp》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...