JsFiddle: http: //jsfiddle.net/shabbirrangwala/h9uaQ/19/ 我试图每行只添加 50 个字符和 17 行,我想以图像的形式获得输出。不知何故,行和列不受限制。我在这里做错了什么?
示例代码:
tCtxt.canvas.width = tCtxt.measureText(this.value).width;
var t = this.value.split('\n');
tCtxt.canvas.height = t.length*15;
tCtxt.font = "12px monospace";
tCtxt.fillStyle = "black";
var y = 12;
for(var i=0; i<t.length; i++, y+=12) {
tCtxt.fillText(t[i], 0, y);
}
imageElem.src = tCtxt.canvas.toDataURL();