码迷,mamicode.com
首页 > Windows程序 > 详细

VS2015 C#利用QrCodeNet生成QR Code

时间:2018-05-21 17:58:21      阅读:559      评论:0      收藏:0      [点我收藏+]

标签:nbsp   opened   ima   def   lap   .net   pen   aging   creat   

Step by step Create QR Code with QrCodeNet

Step.1 新建項目

技术分享图片

Step.2 在窗口中拖入一個Button

技术分享图片

Step.3 下載QrCodeNet代碼,解壓\QrCodeNet\sourceCode\qrcodenet\Gma.QrCodeNet\nuget\lib\net45\Gma.QrCodeNet.Encoding.dll

技术分享图片

Step.4 加入參考(引用)

技术分享图片

Step.5 添中using

using Gma.QrCodeNet.Encoding;
using Gma.QrCodeNet.Encoding.Windows.Render;
using System.IO;

Step.6 粘貼代碼

技术分享图片
 1 public partial class Form1 : Form
 2     {
 3         const string str = "160-12345678-8888,AbcdefgHijklmnOpqRst,2018/05/21";
 4         public Form1()
 5         {
 6             InitializeComponent();
 7         }
 8         protected override void OnPaint(PaintEventArgs e)
 9         {
10             base.OnPaint(e);
11             ShowCode(e.Graphics);
12         }
13         private void ShowCode(Graphics g)
14         {
15             QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.L);
16             QrCode qrCode = qrEncoder.Encode(str);
17 
18             FixedModuleSize moduleSize = new FixedModuleSize(2, QuietZoneModules.Two);
19             GraphicsRenderer render = new GraphicsRenderer(moduleSize, Brushes.Black, Brushes.White);
20             render.Draw(g, qrCode.Matrix);
21         }
22 
23         private void btnSaveFile_Click(object sender, EventArgs e)
24         {
25             QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.L);
26             QrCode code = new QrCode();
27             qrEncoder.TryEncode(str, out code);
28 
29             const int modelSizeInPixels = 4;
30 
31             GraphicsRenderer render = new GraphicsRenderer(
32                 new FixedModuleSize(modelSizeInPixels, QuietZoneModules.Two),
33                 Brushes.Black,
34                 Brushes.White);
35 
36             string fileName = Application.ExecutablePath + "New.png";
37 
38             using (FileStream stream = new FileStream(fileName, FileMode.Create))
39             {
40                 render.WriteToStream(code.Matrix, System.Drawing.Imaging.ImageFormat.Png, stream);
41             }
42         }
43     }
View Code

Step.7 運行結果

技术分享图片

 

技术分享图片

 

參考資料:

QR Code

http://www.qrcode.com/zh/about/

C#利用QrCode.Net生成二维码(Qr码)

https://www.cnblogs.com/tianma3798/p/4054270.html

利用QrCode.Net生成二维码 asp.net mvc c#

https://blog.csdn.net/paolei/article/details/12584295

草料二维码

https://cli.im/

VB.Net创建和调用DLL教程

https://blog.csdn.net/namecgc/article/details/77940698

VS2015 C#利用QrCodeNet生成QR Code

标签:nbsp   opened   ima   def   lap   .net   pen   aging   creat   

原文地址:https://www.cnblogs.com/keepee/p/9068257.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!