2013-04-03 52 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();