时间:2019-05-03 来源:小程序工厂
wxml://////////////
js://////////////
c_canvas:function(){
var that=this;
that.setData({d_c:true})
getApp().loading("请稍等……",30000)
wx.getImageInfo({
src: 'https://bmob-cdn-22087.bmobcloud.com/2018/11/28/98a3a696407c069080eabb219515a088.jpg',
success(res0){
wx.getImageInfo({
src: that.data.img,
success(res) {
console.log(res)
const cts = wx.createCanvasContext('myCanvas')
cts.setFillStyle('white');
cts.fillRect(0, 0, 200, 323.6);
//上面是画背景
cts.drawImage(res.path,6, 5, 350, res.height / res.width * 350)
//画图片
cts.drawImage(res0.path, 5, res.height / res.width * 350+15, 100, 100)
//画二维码
cts.setFillStyle('black')
cts.setFontSize(20);
cts.setTextAlign('left');
cts.fillText(that.data.title, 130, res.height / res.width * 350 + 50);
cts.fillText("--" + that.data.userNickName, 350 - that.data.userNickName.length * 15, res.height / res.width * 350 + 110);
//画标题和名字
that.setData({ c_height: (res.height / res.width * 350 + 130)*1.8})
cts.draw(false, function (e) {
wx.canvasToTempFilePath({
canvasId: 'myCanvas',
success: function (res) {
// 获得图片临时路径
that.data.canvasimg = res.tempFilePath;
}
})
});
wx.hideToast()
console.log(res.height)
}
})
}
})
},
share:function(){
wx.saveImageToPhotosAlbum({
filePath: this.data.canvasimg,
success(res) {
console.log(res.errMsg)
},
fail(res) {
console.log(res.errMsg)
}
})
},
能做个代码片段吗?
可能是你存图不是在 ctx.draw(false,callback)的callback里,也可能是你尺寸算错了