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();
答案 0 :(得分:0)
尝试将wrap =“hard”添加到textarea标记以强制在断点处插入新行