共计 407 个字符,预计需要花费 2 分钟才能阅读完成。
一般来说 绘制很多张图片 中间有几张没画出来 通常就是没 load 得原因,具体如下:
let arr = [‘img1′,’img2′,’img3’];
let Canvas = document.createElement(‘canvas’);
ctx = Canvas.getContext(“2d”);
let {W, H} = {100, 200};
let scaleBy = 2;
arr.forEach(e => {
let bgImg = document.creatElement(‘img’);
bgImg.src = e;
bgImg.onload = () => {
ctx.drawImage(bgImg, 0, 0, W * scaleBy, H * scaleBy);
let newImg = document.createElement(‘img’);
newImg.src = Canvas.toDataURL();
document.body.appendChild(newImg);
}
})
正文完
发表至: javascript
2019-01-17