随笔 - 435  文章 - 0  评论 - 111  阅读 - 62万 

微信小程序客户端生成二维码的方法, 请参考这里: https://github.com/demi520/wxapp-qrcode  代码片段如下:

复制代码
const QR = require("../../utils/qrcode.js");

createQrCode: function (url, canvasId, cavW, cavH) {
    //调用插件中的draw方法,绘制二维码图片
    QR.api.draw(url, canvasId, cavW, cavH);
    setTimeout(() => { this.canvasToTempImage(); }, 1000);

  },
  //获取临时缓存照片路径,存入data中
  canvasToTempImage: function () {
    var that = this;
    wx.canvasToTempFilePath({
      canvasId: 'mycanvas',
      success: function (res) {
        var tempFilePath = res.tempFilePath;
        console.log(tempFilePath);
        that.setData({
          imagePath: tempFilePath,
          // canvasHidden:true
        });
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },
  //点击图片进行预览,长按保存分享图片
  previewImg: function (e) {
    var img = this.data.imagePath;
    console.log(img);
    wx.previewImage({
      current: img, // 当前显示图片的http链接
      urls: [img] // 需要预览的图片http链接列表
    })
  },
复制代码

 

另一个方案: net core 服务器端生成二维码图片, 小程序显示图片

复制代码
        private void GenerateQRCode(string CustomOrderNumber, string code)
        {
            //You only need five lines of code, to generate and view your first QR code.
            QRCodeGenerator qrGenerator = new QRCodeGenerator();
            QRCodeData qrCodeData = qrGenerator.CreateQrCode(code, QRCodeGenerator.ECCLevel.Q);
            QRCode qrCode = new QRCode(qrCodeData);
            Bitmap qrCodeImage = qrCode.GetGraphic(20);

            var filepath = _host.WebRootPath + "\\images\\qrcode\\" + CustomOrderNumber + "_" + code + ".jpg";
            FileStream fs = new FileStream(filepath, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write);
            qrCodeImage.Save(fs, System.Drawing.Imaging.ImageFormat.Jpeg);
            fs.Close();
            qrCodeImage.Dispose();

           
        }
复制代码

Nuget引用 QRCoder,现在最新版本是1.3.5 ,需要引用 System.Drawing.Common.dll.  这个发布时,记得把发布目录下的runtime目录整个 上传到服务器.(windows服务器应该是用到    runtimes\win\lib\netcoreapp2.0)

posted on   Gu  阅读(3780)  评论(0编辑  收藏  举报
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
历史上的今天:
2017-11-26 微信支付
点击右上角即可分享
微信分享提示