赞
踩
canvasToTempFilePath:fail fail canvas is empty
如果是canvas 2d 写
canvas: this.canvas,
,如果是旧版写canvasId: '***',
wx.canvasToTempFilePath({
canvas: this.canvas,
success(res) {
console.log(res.tempFilePath);
},
fail(err) {
console.log("错误", err);
},
});
// 图片对象
const image = canvas.createImage()
// 图片加载完成回调
image.onload = () => {
// 将图片绘制到 canvas 上
ctx.drawImage(image, 0, 0)
}
// 设置图片src
image.src = 'https://open.weixin.qq.com/zh_CN/htmledition/res/assets/res-design-download/icon64_wx_logo.png'
2.图片需要变动的情况
// 使用这种方式,不要每次都重新createImage
this._icon.bgImage =
this._icon.bgImage ||
(await this.getimg(this.data.bgImage, this.canvas));
this.ctx.drawImage(
this._icon.bgImage,
0,
0,
this.toPx(this.data.width),
this.toPx(this.data.height)
);
// 封装的绘制图片
async getimg(src, canvas) {
return new Promise((resolve, reject) => {
let img = canvas.createImage();
img.onload = () => {
resolve(img);
};
img.src = src;
});
},
在
真机
的情况下才可以看的出同层渲染的效果
如果是旧的canvas可以使用draw的箭头函数来解决
this.ctx.draw(false, () => {
this.process();
});
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。