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

后端 未结 2 534
旧巷少年郎
旧巷少年郎 2021-01-19 14:22

I recently asked a question on how to draw an image larger than my canvas onto the canvas without cropping and save the image back into its original dimensions after perform

相关标签:
2条回答
  • 2021-01-19 14:57

    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)

    0 讨论(0)
  • 2021-01-19 15:03

    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.

    0 讨论(0)
提交回复
热议问题