有任何疑问请去我的新博客提出 https://blog.clso.fun/posts/2019-03-03/vb-net-zxing-net-qr-maker.html

ZXing .NET 的项目主页
https://github.com/micjahn/ZXing.Net

代码基本上抄袭自下面两篇文章 XD
http://www.cnblogs.com/tianma3798/p/5426869.html
http://www.cnblogs.com/tianma3798/p/5426880.html

仅作参数优化,更加实用和简便一点

, , ) As Bitmap
    Dim writer As New ZXing.BarcodeWriter
    writer.Format = ZXing.BarcodeFormat.QR_CODE

    Dim opt As New ZXing.QrCode.QrCodeEncodingOptions
    opt.DisableECI = True '设置为True才可以调整编码
    opt.CharacterSet = "UTF-8" '文本编码,建议设置为UTF-8
    opt.Width = width    '宽度
    opt.Height = height    '高度
    opt.Margin = margin    '边距,貌似不是像素格式,因此不宜设置过大

    writer.Options = opt

    Return writer.Write(qrtext)
End Function

, , ) As Bitmap
    If logo Is Nothing Then
        Return MakeQR(qrtext, width, height, margin)
    End If

    Dim writer As New ZXing.MultiFormatWriter
    Dim hint As New Dictionary(Of ZXing.EncodeHintType, Object)()
    hint.Add(ZXing.EncodeHintType.CHARACTER_SET, "UTF-8")
    hint.Add(ZXing.EncodeHintType.MARGIN, margin)
    hint.Add(ZXing.EncodeHintType.ERROR_CORRECTION, ZXing.QrCode.Internal.ErrorCorrectionLevel.H)

    ' 生成二维码
    Dim bm As ZXing.Common.BitMatrix = writer.encode(qrtext, ZXing.BarcodeFormat.QR_CODE, width, height, hint)
    Dim barcodeWriter = New ZXing.BarcodeWriter()
    Dim bmp As Bitmap = barcodeWriter.Write(bm)

    '获取二维码实际尺寸(去掉二维码两边空白后的实际尺寸)
    Dim rectangle As Integer() = bm.getEnclosingRectangle()

    '计算插入图片的大小和位置
    ) / 3.5), logo.Width)
    ) / 3.5), logo.Height)

    '将img转换成bmp格式,否则后面无法创建Graphics对象
    Dim bmpimg As New Bitmap(bmp.Width, bmp.Height, Imaging.PixelFormat.Format32bppArgb)

    Using g As Graphics = Graphics.FromImage(bmpimg)
        g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
        g.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
        g.CompositingQuality = Drawing2D.CompositingQuality.HighQuality
        g.DrawImage(bmp, , )
    End Using

    '将二维码插入图片
    Using myGraphic As Graphics = Graphics.FromImage(bmpimg)
        '白底
        myGraphic.FillRectangle(Brushes.White, middleL, middleT, middleW, middleH)
        myGraphic.DrawImage(logo, middleL, middleT, middleW, middleH)
    End Using

    bmp.Dispose()

    Return bmpimg

End Function

Shared Function ReadQR(ByVal bmp As Bitmap) As String
    Dim reader As New ZXing.BarcodeReader
    reader.Options.CharacterSet = "UTF-8"

    Dim ret As ZXing.Result = reader.Decode(bmp)
    If ret Is Nothing Then
        Return Nothing
    Else
        Return ret.Text
    End If
End Function

【VB.NET】利用 ZXing.Net 生成二维码(支持自定义LOGO)的更多相关文章

  1. 使用PHP生成二维码支持自定义logo

    require_once 'phpqrcode/phpqrcode.php'; //引入类库 $text = "https://www.baidu.com/";//要生成二维码的文 ...

  2. 基于Asp.Net Core,利用ZXing来生成二维码的一般流程

    本文主要介绍如何在.net环境下,基于Asp.Net Core,利用ZXing来生成二维码的一般操作.对二维码工作原理了解,详情见:https://blog.csdn.net/weixin_36191 ...

  3. C# ZXing.Net生成二维码、识别二维码、生成带Logo的二维码(二)

    1.使用ZXint.Net生成带logo的二维码 /// <summary> /// 生成带Logo的二维码 /// </summary> /// <param name ...

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

    利用QrCode.Net生成二维码 asp.net mvc c# 里面介绍了.net的方式及js的方式,还不错. 里面用到的qrcode.net的类库下载地址:https://qrcodenet.co ...

  5. 利用google api生成二维码名片

    利用google api生成二维码名片 二维条码/二维码可以分为堆叠式/行排式二维条码和矩阵式二维条码.堆叠式/行排式二维条码形态上是由多行短截的一维条码堆叠而成:矩阵式二维条码以矩阵的形式组成,在矩 ...

  6. 使用jquery-qrcode在页面上生成二维码,支持中文

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. php--------php库生成二维码和有logo的二维码

    php生成二维码和带有logo的二维码,上一篇博客讲的是js实现二维码:php--------使用js生成二维码. 今天写的这个小案例是使用php库生成二维码: 效果图:        使用了 php ...

  8. C#Qrcode生成二维码支持中文,带图片,带文字

    C#Qrcode生成二维码支持中文带图片的操作请看二楼的帖子,当然开始需要下载一下C#Qrcode的源码 下载地址 : http://www.codeproject.com/Articles/2057 ...

  9. 利用Spring Boot+zxing,生成二维码还能这么简单

    在网站开发中,经常会遇到要生成二维码的情况,比如要使用微信支付.网页登录等,本文分享一个Spring Boot生成二维码的例子,这里用到了google的zxing工具类. 本文目录 一.二维码简介二. ...

随机推荐

  1. 通过java.util.Properties类来读取.properties文件中key对应的value

    转:http://www.cnblogs.com/panjun-Donet/archive/2009/07/17/1525597.html

  2. Squares of a Sorted Array LT977

    Given an array of integers A sorted in non-decreasing order, return an array of the squares of each ...

  3. netty1 快速入门

    Netty是一个高性能.异步事件驱动的网路通信框架 ,由于精力有限,本人并没有对其源 码做了特别细致的研究.如果下面的内容有错误或不严谨的地方,也请大家指正和谅解. Netty的线程模型是Reacto ...

  4. python之排列组合测试

    # test permutations and combinations import itertools as it for i in it.combinations('abcd',2): prin ...

  5. spring学习 十六 spring加载属性文件

    第一步:创建一个properties文件,以数据库链接作为实例db.properties jdbc.url=jdbc:mysql://192.168.153.128:3306/mybaties?cha ...

  6. css进阶篇

    一.css的属性值 1)字体属性 font-size: 5px; /* 字体大小 */ font-size: 20px/50%/larger /* 字体的大小 */ font-family:'Luci ...

  7. oracle unix时间戳与date转换

    linux 时间戳 转date:   创建自定义函数: create or replace function unix_to_oracle(in_number number) return date ...

  8. idea中使用thymeleaf标签时有红色的波浪线怎么去掉

    使用最新版本的idea2017可以解决,方法如下: 选择File->Settings->Editor->Inspections,然后搜索thymeleaf 将Expression v ...

  9. js 获取数组最后一个元素

    当然有很多中做法 我这边就随便写几个最常用 最简单的方法把 # shift 删除数组第一个元素,并返回该元素,跟pop差不多 var a = ["aa","bb" ...

  10. aliyun API 调试

    打开https://ai.aliyun.com/,登录阿里云账号,选择控制台,右侧标签中选择产品服务,选择自己需要的子标签(如图像识别),选择API调试,按要求填写表格. 其中请求Body参照API文 ...