const ctx = uni.createCanvasContext('myCanvas');
ctx.clearRect(0,0,that.canvasWidth,that.canvasHeight)
// 绘制海报
ctx.drawImage(posterinfo.path, 0, 0, posterinfo.width, posterinfo.height);
ctx.save();
// 绘制二维码
var codeWidth = 150;
var codeHeight = 150;
var codeX = that.canvasWidth - 25 - codeWidth; //二维码x坐标
var codeY = 25; //二维码y坐标
var arcR = codeWidth / 2;
ctx.beginPath();
ctx.arc(codeX + arcR, codeY + arcR, arcR, 0, 2 * Math.PI);
ctx.setFillStyle('rgba(255,255,255,0.6)');
ctx.fill();
ctx.drawImage(codeinfo.path, codeX, codeY, codeWidth, codeHeight);
console.log(posterinfo.path, codeinfo.path);
ctx.draw(false,()=>{
uni.canvasToTempFilePath({
canvasId:'myCanvas',
x:0,
y:0,
width:that.canvasWidth,
height:that.canvasHeigh,
destWidth:that.canvasWidth,
destHeight:that.canvasHeight,
fileType:'jpg',
success(res){
that.canvasImg = res.tempFilePath
console.log(res.tempFilePath)
resolve(res.tempFilePath)
},fail(err) {
reject(err)
}
})
});
appid多少呢,我们看看哈
ctx.draw(false,()=>{ setTimeout(()=>{ //uni.canvasToTempFilePath .... },300) }); 加个延时