Canvas set the width and height of the problem!

The default width of the Canvas element is 300px and the height is 150px. To set its width and height, you can use the following methods:
Method 1:
1 <canvas width="500" height="500"$amp;>amp;$lt;/canvas>
Method 2: Use HTML5 Canvas API operation
1 var canvas = document.getElementById('the id of the canvas to be operated');
2 canvas.width = 500;
3 canvas.width = 500;

If the width and height are set by the following method, the Canvas element will be stretched from the original size to the set width and height : Method 1 :
It will be stretched using CSS ; 4 }



Also includes style="" in inline styles. That is, the above example will also produce stretching.
Method 2: Using the HTML5 Canvas API operation will be stretched
1 var canvas = document.getElementById('the id of the canvas you want to operate');
2 canvas.style.width = "1000px";
3 canvas.style.height = "1000px" ;
Method 3: Use jquery's $("#id").width(500); it will be stretched 

Others: The width and height of the canvas cannot be expressed in percentages. The canvas will display the percentage value as a numerical value

 

Original URL: https://www.cnblogs.com/JamKong/p/4987163.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326396640&siteId=291194637