canvas 模拟 真机 调试都能出来 就是预览模式出不来
发布于 4 年前 作者 hmeng 11852 次浏览 来自 问答
async onLoad(){
    var that = this;
    wx.downloadFile({
      url: that.imgStr, // 资源地址
      success(res) {
        // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
        if (res.statusCode === 200) {
          that.imgFilePath =  res.tempFilePath;
          that.$apply();
          that.drawImg();
          console.log(res);
        }
      }
    })
    that.$apply();
       
      
       /* ctx.draw(false, function () {
        // wx.canvasToTempFilePath这个一定要写在ctx.draw里面的回调里面,是坑勿跳
        wx.canvasToTempFilePath({
            canvasId: "shareCanvas",
            destWidth: 600,
            destHeight: 800,
            quality: 1,
            success: function (res) {
                console.log(res.tempFilePath)
                callback(res.tempFilePath)
            },
            fail: function (res) {
                console.log(res)
            }
        })
    })  */
 
  }
 
async drawImg(){
      var postersize = this.setCanvasSize(750);//动态设置画布大小
      console.log(postersize);
      const ctx = wx.createCanvasContext('shareCanvas',this);
 
      console.log(this.imgFilePath);
       
      ctx.drawImage(this.imgFilePath, 0, 0, postersize.w, postersize.h);
      ctx.drawImage(this.imgFilePath, 30, 30, postersize.w, postersize.h);
      console.log(this.imgFilePath);
      ctx.draw();
}
2 回复

点右上角的…,有个 打开调试。。。

大神啊 请快帮忙啊  崩溃了

回到顶部