前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >VS2015 VB.Net利用QrCodeNet生成QR Code

VS2015 VB.Net利用QrCodeNet生成QR Code

作者头像
DotNet Whisperer
发布2024-08-14 15:29:38
750
发布2024-08-14 15:29:38
举报
文章被收录于专栏:DotNet杂记

Step by step Create QR Code with QrCodeNet

Step.1 新建項目

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

Step.3 加入參考(引用)

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

Step.5 添中 Imports

代码语言:javascript
复制
Imports Gma.QrCodeNet.Encoding
Imports Gma.QrCodeNet.Encoding.Windows.Render
Imports System.IO

Step.6 粘貼代碼

代码语言:javascript
复制
 1 Public Class Form1 : Inherits Form
 2 
 3     ' // 定義常量
 4     Public Const str = "160-12345678-8888,AbcdefgHijklmnOpqRst,2018/05/22.160-12345678-8888,AbcdefgHijklmnOpqRst,2018/05/22."
 5 
 6     ' // 重寫 OnPaint 方法,增加繪制二維碼方法調用
 7     Protected Overrides Sub OnPaint(e As PaintEventArgs)
 8         MyBase.OnPaint(e)
 9 
10         ' // 繪制二維碼
11         Call ShowQrCode(e.Graphics)
12 
13         tbStrContent.Text = str
14 
15     End Sub
16 
17     ' // Save File 按鈕事件
18     Private Sub btnSaveFile_Click(sender As Object, e As EventArgs) Handles btnSaveFile.Click
19 
20         Const moduleSizeInPixels = 4
21 
22         Dim qrEncoder As New QrEncoder(ErrorCorrectionLevel.L)
23         Dim qrCode As New QrCode()
24 
25         Dim moduleSize As New FixedModuleSize(moduleSizeInPixels, QuietZoneModules.Two)
26         Dim render As New GraphicsRenderer(moduleSize, Brushes.Black, Brushes.White)
27 
28         Dim fileName As String = Application.ExecutablePath + "_One.png"
29 
30         ' // 錯誤繼續執行
31         On Error Resume Next
32 
33         ' // 根據字符串生成 QR Code
34         qrEncoder.TryEncode(str, qrCode)
35 
36         ' // 寫入文件
37         Using stream As New FileStream(fileName, FileMode.Create)
38             render.WriteToStream(qrCode.Matrix, System.Drawing.Imaging.ImageFormat.Png, stream)
39         End Using
40 
41     End Sub
42 
43     ' // 繪制二維碼
44     Private Sub ShowQrCode(g As Graphics)
45         Dim qrEncoder As New QrEncoder(ErrorCorrectionLevel.L)
46         Dim qrCode As New QrCode()
47 
48         Dim moduleSize As New FixedModuleSize(2, QuietZoneModules.Two)
49         Dim render As New GraphicsRenderer(moduleSize, Brushes.Black, Brushes.White)
50 
51         ' // 根據字符串生成 QR Code
52         qrCode = qrEncoder.Encode(str)
53 
54         ' // 描繪 QR Code
55         render.Draw(g, qrCode.Matrix)
56 
57     End Sub
58 
59 End Class

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

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018-05-22,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档