我正在尝试将textarea内容放入画布,但是在canvas块上获取未定义的消息。成功加载图像但不是textarea。我试过很多方法来解决这个问题,但无法解决。请帮我。在此先感谢。
html代码
<textarea>praise the lord</textarea>
<div > <button class="wrapper1" id="saveid" onclick="sharee(0)">SAVE </button> </div>
<img id="scream" src="a.jpg" alt="The Scream" width="70" height="70"><p>Canvas:</p>
<canvas id="myCanvas" width="300" height="300" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>
javascript代码
function sharee() {
var val = document.getElementById("myCanvas");
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
var img = document.getElementById("scream");
textArea = document.getElementsByTagName("textarea")[0],
ctx.font="30px Arial";
ctx.drawImage(img, 40, 40);
ctx.fillText(textarea, 40,60);
setTimeout(function(){
window.savephotoplugin(canvas,"image/png",device.version,function(val){
//returns you the saved path in val
alert("Photo Saved: " + val);
});
}, 0)
答案 0 :(得分:1)
您正试图将自己的textarea
元素绘制为不起作用的文本。
尝试此修改:
ctx.fillText(textArea.value, 40, 60);
我不确定这只是帖子中的错字,但这一行必须是:
var textArea = document.getElementsByTagName("textarea")[0]; //no comma at end