收藏
回答

鸿蒙next系统5.1.0微信1.0.9,canvas 上绘制二维码显示不出来?鸿蒙都不能用了?

createqr2: function (w, h, qrid, text, cb) {

  const query = wx.createSelectorQuery().in(this);

  var qid = '#' + qrid;

  query.select(qid)

    .fields({ node: true, size: true })

    .exec((res) => {

      const canvas = res[0].node;

      const ctx = canvas.getContext('2d');

      //const dpr = wx.getSystemInfoSync().pixelRatio || 1;

      const { pixelRatio: dpr } = wx.getWindowInfo();


      // 物理像素大小

      canvas.width = w * dpr;

      canvas.height = h * dpr;

      ctx.scale(dpr, dpr);


      drawQrcode({

        canvas: canvas,

        width: w,

        height: h,

        padding: 30,

        background: '#ffffff',

        foreground: '#000000',

        text: text

      });


      // 保存二维码到临时路径

      wx.canvasToTempFilePath({

        canvas: canvas,   // 传节点对象即可

        x: 0,

        y: 0,

        width: w,

        height: h,

        destWidth: w * dpr,

        destHeight: h * dpr,

        success(res) {

          cb(0, res.tempFilePath);

          console.log('二维码临时路径:', res.tempFilePath);

        },

        fail(err) {

          cb(1, '');

          console.error(err);

        }

      });

    });

},

回答关注问题邀请回答
收藏

1 个回答

  • 智能回答 智能回答 本次回答由AI生成
    08-13
    有用
    回复
登录 后发表内容