html5 canvas is not showing full image

前端 未结 2 490
遇见更好的自我
遇见更好的自我 2020-12-11 17:17

My image size is 940 * 300 but html5 canvas showing only part of image in chrome. Can you please help how to fix this?

Below is the code



        
2条回答
  •  無奈伤痛
    2020-12-11 17:29

    The reason is simply that you cannot do

      ctx.width= imgWidth;
      ctx.height=imgHeight;
    

    You must do

      can.width= imgWidth;
      can.height=imgHeight;
    

    Where can is a reference to the canvas, and not the canvas context.

    Working example:

    http://jsfiddle.net/rbNzb/

提交回复
热议问题