画布到图:未捕获的DOMException

时间:2019-02-28 14:34:19

标签: javascript jquery html canvas html5-canvas

如果我想将HTML画布图形转换为图像,则会出现未捕获的DOMException: “无法在'HTMLCanvasElement'上执行'toDataURL':可能无法导出污染的画布。”

我的代码:

HTML:

<div id=canvasDiv  style="width:1700px height:800px; overflow: auto; border:1px solid #d3d3d3; margin: 10px 10px 10px 10px;">
<canvas id="myCanvas" height="800" width="5000">Your browser does not support the HTML5 canvas tag.</canvas>
</div>

JS:

 <script>
 var canvas = document.getElementById('myCanvas');
 var context = canvas.getContext('2d');
    ...
download.addEventListener("click", function() {
 var imgData = canvas.toDataURL("image/JPEG", 1.0);
 var pdf = new jsPDF();
  pdf.addImage(imgData, 'JPEG', 0, 0);
 var download = document.getElementById('download');
  pdf.save("download.pdf");
 }, false); 
</script>

谢谢!

0 个答案:

没有答案