- 当前 Bug 的表现(可附上截图)
-在开发工具里是正常的,但是在我荣耀10上预览怎么黑了,背景去哪了?只有图片了?代码就这几行,是哪里写的有问题?
- 提供一个最简复现 Demo
const ctx = canvas.getContext('2d');
ctx.fillStyle = '#d3c6a6';
ctx.fillRect(0, 50, 500, 500);
const image = wx.createImage();
image.src = 'images/rc_icon_sangong.png';
image.onload = function () {
ctx.drawImage(image, 0, 0, 50, 50,
0,
50,
50,
50)
}
都没一个人回答。。我已经自己找到方法了
export default class Main {
constructor() {
this.image = wx.createImage();
this.image.src = 'images/rc_icon_sangong.png';
var that=this;
this.image.onload = function(){
that.initstar()
};
}
initstar() {
const ctx = canvas.getContext('2d');
ctx.fillStyle = '#d3c6a6';
ctx.fillRect(0, 50, 512, 512);
ctx.drawImage(this.image, 0, 0, 50, 50, 0, 50, 50, 50);
}
}