同求
wx.compressImage图片压缩功能不完善,不能进行尺寸大小压缩?wx.compressImage目前只能进行质量压缩,华为P30的照片有7000多像素,图片压缩后还有10多兆,要有进行像素大小压缩的比较好,或者压缩时能够控制图片文件大小。
2020-06-18这里想显示 有2个地方需要注意 1.createCanvasContext需要传入this作为第二个参数wx.createCanvasContext('shareCanvas',this); 2.画图之前需要先获取信息 wx.getImageInfo
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() {[代码][代码] [代码][代码]}[代码][代码] [代码][代码]});[代码][代码] [代码][代码]},[代码]
2020-06-18