2013-04-03 51 views
0

我想着色下面一行,但是我的画布要么为所有线条着色,要么根本不着色。任何帮助,将不胜感激在画布上着色线条

canvas.save(); 
canvas.scale(1, 0.75); 
canvas.beginPath(); 
canvas.arc(100, 95, 8, 0, Math.PI * 2, false); 
canvas.stroke(); 
canvas.strokeStyle= "red"; 
canvas.closePath(); 
canvas.restore(); 
+0

我没有看到任何企图在这里着色的行。你做了一个吗? – Bergi 2013-04-03 20:31:39

+0

是的,我尝试过,我试过 – user2193106 2013-04-03 20:35:21

+0

canvas.fillStyle =“red”; – user2193106 2013-04-03 20:36:02

回答

1

您正在使用画布,我假设你的意思上下文。

canvas = getElementById(“mycanvas”);

context.getContext(“2d”);

几点: 1.使用context.beginPath()开始1次或多次绘制; 2.当你将上下文告诉context.stroke()时,它将使用你设置的strokeStyle(上一个strokeStyles被忽略) 3.总是使用context.stroke()来物理应用你绘制的线条,弧线,等画布。

// draw a red circle 
context.beginPath(); 
context.arc(100, 95, 8, 0, Math.PI * 2, false); 
context.strokeStyle="red"; 
context.stroke(); 

//then begin a new path and draw a blue circle 
context.beginPath(); 
context.arc(150, 95, 8, 0, Math.PI * 2, false); 
context.strokeStyle="blue"; 
context.stroke();