【发布时间】:2017-01-28 13:35:00
【问题描述】:
我在向一个画布添加多幅绘图时遇到问题。我做了一些例子: https://jsfiddle.net/ym5q9ktp/
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 代码的最后一行绘制第二条红线。如何解决?
【问题讨论】:
标签: javascript html canvas drawimage