[英]HTML5 canvas perform inconsistent when define its width and height using ID selector
我的html文件非常简单:
<body>
<canvas id="canvas" width="900" height="400"></canvas>
<button onclick="DrawSVG()">Draw SVG</button>
</body>
当单击按钮时,我使用canvg.js在画布上绘制SVG。
var opts = {
ignoreMouse: false,
ignoreClear: true,
ignoreDimensions : true,
offsetX: 0,
offsetY: 0
};
canvg(canvas, "face.svg", opts);
face.svg:
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" >
<rect x="0" y="0" width="80" height="80" rx="6" fill="blue" stroke="red" stroke-
width="1px" fill-opacity="0.7" />
</svg>
看来是对的。
但是当我定义头部的宽度和高度时:
<style type="text/css">
#canvas {
width: 900px;
height: 400px;
}
画布上的svg比以前大4倍。 有什么不同?
说明在这里: http : //www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#attr-canvas-width
canvas元素的固有尺寸等于坐标空间的大小,其数字以CSS像素表示。 但是,可以通过样式表任意设置元素的大小。 在渲染期间,将缩放图像以适合此布局大小。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.