2
我在添加多个图形到一个画布时遇到问题。我做了一些例子: https://jsfiddle.net/ym5q9ktp/将多个drawImage()添加到一个画布中
HTML:
<canvas id="myCanvas" width="240" height="297" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.
</canvas>
JS:
function lc(canv, x1, y1, x2, y2) {
c = canv.getContext("2d");
c.beginPath();
c.moveTo(x1, y1);
c.lineTo(x2, y2);
c.strokeStyle = "red";
c.stroke();
return c
}
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.beginPath();
ctx.moveTo(0, 0);
ctx.lineTo(200, 100);
ctx.stroke();
ctx.drawImage(lc(canvas, 15, 56, 56, 75), 10, 10);
ctx.drawImage(lc(canvas, 25, 56, 156, 95), 80, 80);
代码不拉丝在js代码最后一行第二红线。如何解决它?
谢谢,它的工作方式:) – Michal