canvas绘制多张图其中有空缺或绘制不成功的题目

一般来说 绘制很多张图片 中心有几张没画出来 一般就是没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);
    }
})
    原文作者:不会飞的Porco
    原文地址: https://segmentfault.com/a/1190000017928161
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞