使用QRCode生成二维码
2016-11-16 16:54
405 查看
第一步: 获取QRCode组件
可以通过vs的nuget管理安装Gma.QrCodeNet,
也可以直接添加"Gma.QrCodeNet.Encoding.dll"的引用.
第二步:封装操作方法,编写QRCodeHelper帮助类(直接复制,黏贴即可)
第三步: 测试调用,生成二维码图片
补充:
如果想通过js动态生成二维码,可使用jQuery.QRCode插件.说明文档: https://larsjung.de/jquery-qrcode/
QRCode组件下载地址: https://pan.baidu.com/s/1slMrQHJ
可以通过vs的nuget管理安装Gma.QrCodeNet,
也可以直接添加"Gma.QrCodeNet.Encoding.dll"的引用.
第二步:封装操作方法,编写QRCodeHelper帮助类(直接复制,黏贴即可)
/// <summary> /// 含有QR码的描述类和包装编码和渲染 /// </summary> public class QRCodeHelper { /// <summary> /// 获取二维码 /// </summary> /// <param name="strContent">待编码的字符</param> /// <param name="ms">输出流</param> /// <param name="moduleSize">大小</param> ///<returns>True if the encoding succeeded, false if the content is empty or too large to fit in a QR code</returns> public static bool GetQRCode(string strContent,MemoryStream ms, int moduleSize = 12) { ErrorCorrectionLevel Ecl = ErrorCorrectionLevel.M; //误差校正水平 string Content = strContent;//待编码内容 QuietZoneModules QuietZones = QuietZoneModules.Two; //空白区域 var encoder = new QrEncoder(Ecl); QrCode qr; if (encoder.TryEncode(Content, out qr))//对内容进行编码,并保存生成的矩阵 { var render = new GraphicsRenderer(new FixedModuleSize(moduleSize, QuietZones)); render.WriteToStream(qr.Matrix, ImageFormat.Png, ms); } else { return false; } return true; } }
第三步: 测试调用,生成二维码图片
using (var ms = new MemoryStream()) { string strContent = "http://www.baidu.com"; QRCodeHelper.GetQRCode(strContent, ms, 12); Response.ContentType = "image/Png"; Response.OutputStream.Write(ms.GetBuffer(), 0, (int)ms.Length); Response.End(); }
补充:
如果想通过js动态生成二维码,可使用jQuery.QRCode插件.说明文档: https://larsjung.de/jquery-qrcode/
QRCode组件下载地址: https://pan.baidu.com/s/1slMrQHJ
相关文章推荐
- 使用jquery-qrcode生成二维码
- php使用phpqrcode类库生成二维码
- Python3 qrcode的使用(生成二维码)
- 使用jquery-qrcode生成二维码
- 使用phpqrcode生成二维码
- php生成二维码,使用qrcode类库创建
- PHP 使用 phpqrcode生成二维码附在线演示地址
- 使用JS生成二维码QRCode
- 使用PHP QRcode生成二维码广告图
- Python使用QRCode模块生成二维码
- Python使用QRCode生成二维码
- php 使用phpqrcode生成二维码并上传到OSS
- 使用jquery-qrcode在页面上生成二维码,支持中文
- Python使用QRCode模块生成二维码
- 使用jQuery插件qrcode生成的二维码在微信中不能够识别
- 使用PHP生成二维码(PHPQRCode)
- 使用QRCode简单生成二维码
- 使用jQuery的插件qrcode生成二维码(静态+动态生成)及常见问题解决方法
- 使用zxing生成QRCode二维码,在Android的webview中调用条形码扫描(转)
- vue.js中使用QRCode生成二维码