2012-05-04 61 views
0

custom shape in canas画布中的自定义形状?

有什么方法可以在html5画布中使用'bezier曲线'或'二次曲线'创建形状。或者是有什么在画布

+0

你曾经在画布上重新创建过这个形状吗? –

+0

不,我用图像而不是绘制路径 – sumitmann

回答

1

对于多边形你可以使用以下(其中CTX是你的画布的getContext( '2D')):

ctx.fillStyle=*hex code of the color you want it to be"; 
ctx.beginPath(); 
ctx.moveTo(x1,y1); 
ctx.lineTo(x2,y2); 
ctx.lineTo(x3,y3); 
*add more points if needed using a lineTo(x,y) for each of your points* 
ctx.closePath(); 
ctx.fill(); 

如果你想有一个行程多边形使用ctx.strokeStyle和ctx.stroke()而不是ctx.fillStyle和ctx.fill ()