Javascript HTML5画布:为什么我的圆圈没有画出来?

Javascript HTML5画布:为什么我的圆圈没有画出来?,javascript,html5-canvas,Javascript,Html5 Canvas,下面是我的代码的草图。我想在一张图片的上面画一个圆圈。显示了图像,但没有显示圆 ctx=can.getContext('2d'); backpic=document.getElementById('canpic'); ctx.drawImage(backpic,0,0); pos=[100,100]; ctx.save(); ctx.beginPath(); ctx.lineWidth=2; ctx.strokeStyle="green"; ctx.arc(pos[0],pos[1],40,0,

下面是我的代码的草图。我想在一张图片的上面画一个圆圈。显示了图像,但没有显示圆

ctx=can.getContext('2d');
backpic=document.getElementById('canpic');
ctx.drawImage(backpic,0,0);
pos=[100,100];
ctx.save();
ctx.beginPath();
ctx.lineWidth=2;
ctx.strokeStyle="green";
ctx.arc(pos[0],pos[1],40,0,2 * Math.PI,false);
ctx.stroke();
ctx.restore();

我做错了什么?

你的圈子在小提琴上工作

can = document.getElementById("can");
ctx=can.getContext('2d');
pos=[100,100];
ctx.save();
ctx.beginPath();
ctx.lineWidth=2;
ctx.strokeStyle="green";
ctx.arc(pos[0],pos[1],40,0,2 * Math.PI,false);
ctx.stroke();
ctx.restore();

为什么要调用ctx.restore()而不是ctx.Save()?我现在看到错误不在我的代码中。谢谢你指出这一点。