Eric Huang "可以试一下这个API,wx.canvasToTempFilePath(OBJECT, this) 然后在分享配置里 即 Page.onShareAppMessage(Object) 方法指定图片的Url". 刚刚试了下好像不行啊 [代码]Page({[代码][代码] [代码][代码]onReady: [代码][代码]function[代码] [代码](e) {[代码][代码] [代码][代码]// 使用 wx.createContext 获取绘图上下文 context[代码][代码] [代码][代码]var[代码] [代码]context = wx.createCanvasContext([代码][代码]'canvas'[代码][代码])[代码] [代码] [代码][代码]context.setStrokeStyle([代码][代码]"#00ff00"[代码][代码])[代码][代码] [代码][代码]context.setLineWidth(5)[代码][代码] [代码][代码]context.rect(0, 0, 200, 200)[代码][代码] [代码][代码]context.stroke()[代码][代码] [代码][代码]context.setStrokeStyle([代码][代码]"#ff0000"[代码][代码])[代码][代码] [代码][代码]context.setLineWidth(2)[代码][代码] [代码][代码]context.moveTo(160, 100)[代码][代码] [代码][代码]context.arc(100, 100, 60, 0, 2 * Math.PI, [代码][代码]true[代码][代码])[代码][代码] [代码][代码]context.moveTo(140, 100)[代码][代码] [代码][代码]context.arc(100, 100, 40, 0, Math.PI, [代码][代码]false[代码][代码])[代码][代码] [代码][代码]context.moveTo(85, 80)[代码][代码] [代码][代码]context.arc(80, 80, 5, 0, 2 * Math.PI, [代码][代码]true[代码][代码])[代码][代码] [代码][代码]context.moveTo(125, 80)[代码][代码] [代码][代码]context.arc(120, 80, 5, 0, 2 * Math.PI, [代码][代码]true[代码][代码])[代码][代码] [代码][代码]context.stroke()[代码][代码] [代码][代码]context.draw();[代码][代码] [代码][代码]wx.canvasToTempFilePath({[代码][代码] [代码][代码]x: 100,[代码][代码] [代码][代码]y: 200,[代码][代码] [代码][代码]width: 50,[代码][代码] [代码][代码]height: 50,[代码][代码] [代码][代码]destWidth: 100,[代码][代码] [代码][代码]destHeight: 100,[代码][代码] [代码][代码]canvasId: [代码][代码]'canvas'[代码][代码],[代码][代码] [代码][代码]success: [代码][代码]function[代码][代码](res) {[代码][代码] [代码][代码]console.log(res.tempFilePath);[代码][代码] [代码][代码]wx.updateShareMenu({[代码][代码] [代码][代码]title: [代码][代码]'测试'[代码][代码],[代码][代码] [代码][代码]path: [代码][代码]'pages/follow/follow'[代码][代码],[代码][代码] [代码][代码]imageUrl: res.tempFilePath[代码][代码] [代码][代码]})[代码][代码] [代码][代码]}[代码][代码] [代码][代码]})[代码][代码] [代码][代码]},[代码][代码] [代码][代码]onShareAppMessage() {[代码][代码] [代码][代码]return[代码] [代码]{[代码][代码] [代码][代码]title: [代码][代码]'测试'[代码][代码],[代码][代码] [代码][代码]imageUrl: [代码][代码]'https://www.google.com.hk/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png'[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码]});[代码] [代码] [代码] [代码] [代码] 理论上分享的图应该是canvas里面画的图 [图片] 但是好像不行,还是初始的onShareAppMessage里面那张google的图 [图片] 然后打开了wx.canvasToTempFilePath(OBJECT, this) 生成的临时路径(上图右边console的链接),403拒绝了 [图片] 是不是跟权限有关系? 如果你已经实现了这个功能,麻烦指导下[狗头],蟹蟹大锅~
仿今日头条canvas保存图片[图片] canvas能实现这样的吗?
2018-08-29