我不明白为什么下面的代码片段产生不同的结果,因为css会缩放画布放大,
<style> #canvas { width: 800px; height: 600px; } </style> <canvas id="canvas"></canvas>
与这种方法(工作原理)相反:
<canvas id="canvas" width="800px" height="600px"></canvas>
解决方法
解释是这里:
http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#attr-canvas-width在另一个职位,谢谢你!
The intrinsic dimensions of the canvas element equal the size of the coordinate space,with the numbers interpreted in CSS pixels. However,the element can be sized arbitrarily by a style sheet. During rendering,the image is scaled to fit this layout size.