Canvas inline height and width attributes overridden with css styles. Is this is a bug?

限于喜欢 提交于 2019-12-01 20:42:57
pimvdb

This behaviour is commonly used for controlling the size of a canvas:

  • Attributes for resolution
  • CSS for stretching/shrinking

See Canvas width and height in HTML5.

I know its been a long time since the question was asked, but I have another solution that can be used as well.

You can try using the canvasContext.drawImage() function, to resize the image as you draw the image into your canvas.

Syntax: void ctx.drawImage(image, dx, dy, dWidth, dHeight);

  • dx and dy are the destination canvas' x and y coordinates
  • dWidth and dHeight are the dimensions in which your image will be drawn on the canvas.

(If you know the size of the canvas and your image, you can calculate what these values need to be)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!