Make Html5 Canvas and Its contained image responsive across browsers

后端 未结 2 1446
抹茶落季
抹茶落季 2020-12-17 05:27

I have a canvas object that I want to put an image in for a web application. I can get the image loaded, but I\'ve run into 2 problems: The image won\'t stretch to the canva

2条回答
  •  感情败类
    2020-12-17 05:50

    width and height of image are read-only so that won't work.

    Try instead:

     context.drawImage(image, 0, 0, canvas.width, canvas.height);
    

    This will draw the image the same dimension as the canvas is (you don't need to reload the image every time btw. - just load it once globally and reuse the image variable.)

提交回复
热议问题