是否有可能在HTML5画布中获得JUST THE TEXT ELEMENT的宽度和高度?

时间:2015-06-21 23:57:14

标签: html5 canvas text height width

例如,如果我在400 x 400画布上执行此操作,ID为off屏幕:

<canvas id="offscreen" width="400" height="400">
Your crappy browser does not support this!
</canvas>

var fauxCanvas = document.getElementById('offscreen');
var ctx = fauxCanvas.getContext("2d");
ctx.font = "bold 80px Arial";
ctx.fillStyle = "#000000";
ctx.fillText('Hello World', 10, 60);

以下内容无法为我提供新添加的文字高度/宽度!

var rawWidth = parseInt(ctx.width);
console.log("The Raw Width is "+rawWidth);

var rawHeight = parseInt(ctx.height);
console.log("The Raw Height is "+rawHeight);

0 个答案:

没有答案