如何在新版canvas接口使用云储存的图片?
net::ERR_NAME_NOT_RESOLVED
function coverCanvas() {
var headCoUrl = 'cloud://****18635e09448b.jpg';
query.select('#myCanvas')
.fields({
node: true,
size: true
})
.exec(async function () {
let canvas = res[0].node;
let ctx = canvas.getContext('2d');
let imgOb = canvas.createImage();
canvas.width = 100;
canvas.height = 100;
imgOb.onload = () => {
// run other
}
imgOb.onerror = err=>{
// 触发err 错误如截图
}
imgOb.src = await loadImage(headCoUrl);
});
function loadImage(cloudUrl) {
return Promise((resolve, reject) => {
wx.cloud.downloadFile({
fileID: cloudUrl,
success: res => {
resolve(res.tempFilePath)
},
fail: res => reject
});
});
}
}