您解决这个问题了么
canvas在开发工具或者真机打开调试模式就能显示,不打开调试模式显示空白?在网上看了好多,也用了downloadFile,白名单也有添加。但是就是没办法显示。没报任何错。这个是什么原因??? 麻烦请大家帮我看看,弄了一个下午就是没有找出原因?@官方 [代码]success: [代码][代码]function[代码][代码](res) {[代码][代码] [代码][代码]console.log(res.data)[代码][代码] [代码][代码]var[代码] [代码]base64 = wx.arrayBufferToBase64(res.data);[代码][代码] [代码][代码]let qrcodeUrl = [代码][代码]"data:image/png;base64,"[代码] [代码]+ base64;[代码][代码] [代码][代码]qrcodeUrl = qrcodeUrl.replace(/[\r\n]/g, [代码][代码]""[代码][代码]);[代码][代码] [代码][代码]wx.getUserInfo({[代码][代码] [代码][代码]withCredentials: [代码][代码]true[代码][代码],[代码][代码] [代码][代码]lang: [代码][代码]''[代码][代码],[代码][代码] [代码][代码]success: [代码][代码]function[代码][代码](res) {[代码][代码] [代码][代码]var[代码] [代码]avatarUrl = res.userInfo.avatarUrl;[代码][代码] [代码][代码]const ctx = wx.createCanvasContext([代码][代码]'share'[代码][代码]);[代码][代码] [代码][代码]ctx.setFillStyle([代码][代码]'white'[代码][代码])[代码][代码] [代码][代码]ctx.fillRect(0, 0, 580, 710)[代码][代码] [代码][代码]// 绘制小程序码[代码][代码] [代码][代码]_this.canvasQR(ctx, base64)[代码][代码] [代码][代码]// 绘制头像[代码][代码] [代码][代码]_this.canvasAvatar(ctx, avatarUrl, _this)[代码][代码] [代码][代码]ctx.draw([代码][代码]true[代码][代码]) [代码][代码]//绘制[代码][代码] [代码][代码]},[代码][代码]drawCircular: [代码][代码]function[代码][代码](ctx, width, height, x, y, url) {[代码] [代码] [代码][代码]var[代码] [代码]avatarurl_width = width;[代码][代码] [代码][代码]var[代码] [代码]avatarurl_heigth = height;[代码][代码] [代码][代码]var[代码] [代码]avatarurl_x = x;[代码][代码] [代码][代码]var[代码] [代码]avatarurl_y = y;[代码][代码] [代码][代码]ctx.save();[代码][代码] [代码][代码]ctx.beginPath();[代码][代码] [代码][代码]ctx.arc(avatarurl_width / 2 + avatarurl_x, avatarurl_heigth / 2 + avatarurl_y, avatarurl_width / 2, 0, Math.PI * 2, [代码][代码]false[代码][代码]);[代码][代码] [代码][代码]ctx.clip();[代码][代码] [代码][代码]ctx.drawImage(url, avatarurl_x, avatarurl_y, avatarurl_width, avatarurl_heigth);[代码][代码] [代码][代码]ctx.restore();[代码][代码] [代码][代码]},[代码][代码] [代码][代码]// 绘制头像[代码][代码] [代码][代码]canvasAvatar: [代码][代码]function[代码] [代码](ctx, avatarUrl, _this){[代码][代码] [代码][代码]wx.downloadFile({[代码][代码] [代码][代码]url: avatarUrl,[代码][代码] [代码][代码]success: res => {[代码][代码] [代码][代码]var[代码] [代码]path = res.tempFilePath [代码][代码]//临时本地路径[代码][代码] [代码][代码]_this.drawCircular(ctx, 46, 46, 27, 27, path);[代码][代码] [代码][代码]ctx.draw([代码][代码]true[代码][代码]) [代码][代码]//绘制[代码][代码] [代码][代码]},[代码][代码] [代码][代码]fail: res => {[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码] [代码][代码]},[代码][代码] [代码][代码]// 绘制小程序码[代码][代码] [代码][代码]canvasQR: [代码][代码]function[代码] [代码](ctx, base64){[代码][代码] [代码][代码]const filePath = `${wx.env.USER_DATA_PATH}/temp_image.png`;[代码][代码] [代码][代码]wx.getFileSystemManager().writeFile({[代码][代码] [代码][代码]filePath,[代码][代码] [代码][代码]data: base64,[代码][代码] [代码][代码]encoding: [代码][代码]'base64'[代码][代码],[代码][代码] [代码][代码]success() {[代码][代码] [代码][代码]var[代码] [代码]QR = filePath;[代码][代码] [代码][代码]ctx.drawImage(QR, 100, 0, 100, 100);[代码][代码] [代码][代码]},[代码][代码] [代码][代码]fail() {[代码][代码] [代码][代码]}[代码][代码] [代码][代码]});[代码][代码] [代码][代码]},[代码]
2021-05-13