这是我的代码片段:
that.w = width + 'px';
that.h = height + 'px';
that.imageNum = that.imageNumPro();
that.waterMarkTime = that.getTimer();
let ctx = uni.createCanvasContext('firstCanvas'); /** 创建画布 */
//将图片src放到cancas内,宽高为图片大小
ctx.drawImage(tempFilePaths, 0, 0, width, height);
ctx.setFontSize(14);
ctx.setFillStyle('red');
ctx.fillText(that.waterMarkTime + ' ' + that.week, 10, height - 80);
ctx.fillText(that.address, 10, height - 20);
ctx.setFillStyle('blue');
ctx.translate(100, 100);
ctx.rotate(20 * Math.PI / 180);
ctx.fillText(that.imageNum, width / 4, 20);
ctx.draw(false, () => {
setTimeout( () => {
uni.canvasToTempFilePath({
canvasId: 'firstCanvas',
fileType: 'jpg',
quality: 0.2,
success: async (res1) => {
console.log(res1);
var tempFilePath = res1.tempFilePath;
let imageInfo = await that.getFileInfo(res1.tempFilePath);
that.uploadTask(imageUrl, tempFilePath);
},
fail:function(err){
}
});
}, 500);
});
怎么优化呢
异步图片加载没完成,就画上了