for循环canvas渲染图片

canvas 渲染图片之前一定要等图片预加载完成
 for循环之后添加图片
for(let i=0;i<100;i++){
that.gmtImg = 对象 
showTIme = 时间
beginx = X坐标
(function(beginX){
  let img = new Image();
  img.src = that.gmtImg[showTime];
  img.οnlοad=function(){
    console.log(beginX)
      ctx.drawImage(img, beginX, 60, 120, 30);
  }})(beginX);
}

该方法转载自  https://blog.csdn.net/twtcqw2008/article/details/80698824 

你可能感兴趣的:(for循环canvas渲染图片)