Scaling HTML5 canvas width preserving w/h aspect ratio

后端 未结 5 1343

I have a canvas element with dimensions of 979X482px and I\'d like to have it stretch to fit the width of any given browser window, keeping the aspect ratio of width/hight 1

5条回答
  •  说谎
    说谎 (楼主)
    2021-01-02 06:09

    All the previous answers are great, but they won't scale all the images drawn on the canvas proportionally with the new canvas size. If you're using kinetic, I've made a function here = http://www.andy-howard.com/how-to-resize-kinetic-canvas-and-maintain-the-aspect-ratio/

提交回复
热议问题