HTML5 Canvas - How to Draw a line over an image background?

前端 未结 4 2076
梦谈多话
梦谈多话 2020-12-08 22:04

I am trying to draw a line on top of an image background - in an HTML5 Canvas . However always the line gets drawn behind the image . Actually the line gets drawn first and

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-08 22:18

    Totally untested code, but did you tried something like this?

    function drawbackground(canvas, context, onload){
    
        var imagePaper = new Image();
    
    
            imagePaper.onload = function(){
    
    
                context.drawImage(imagePaper,100, 20, 500,500);
                onload(canvas, context);
            };
    
          imagePaper.src = "images/main_timerand3papers.png";
    }
    

    and then call the method like this...

     drawbackground(canvas, context, drawlines);
    

提交回复
热议问题