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); } })
相关推荐
大地飞鸿 2020-11-12
星星有所不知 2020-10-12
jinxiutong 2020-07-26
MIKUScallion 2020-07-05
songfens 2020-07-05
songfens 2020-06-11
songfens 2020-06-08
northwindx 2020-05-31
northwindx 2020-05-31
northwindx 2020-05-27
northwindx 2020-05-25
MIKUScallion 2020-05-25
jinxiutong 2020-05-10
xdyangxiaoromg 2020-05-10
大地飞鸿 2020-05-06
northwindx 2020-04-25