I'm unable to get image in canvas in html5, what to do?

后端 未结 3 987
遇见更好的自我
遇见更好的自我 2020-12-22 06:08

I have checked this code from my w3schools where its working well.

But when I run this code in my browser, it\'s not working.

The image does not get displaye

3条回答
  •  粉色の甜心
    2020-12-22 06:45

    I would use the image directly, instead of taking it out of the -tag

    var c = document.getElementById('myCanvas');
    var ctx = canvas.getContext('2d');
    var imageObj = new Image();
    
    imageObj.onload = function() {
          ctx.drawImage(imageObj, 10, 10);
    };
    imageObj.src = 'flower.jpg';
    

提交回复
热议问题