2011-09-30 92 views
31

我正在创建路径并使用path.moveTo(x, y)path.lineTo(x, y)在每个路径中添加多行。然后canvas.drawPath(path, paint)正在绘制所有路径。但是在一些路径中线之间有1-2像素的空间。我怎样才能删除这些空间?我的代码是类似的东西:如何绘制光滑/圆形的路径?

paint = new Paint(); 
paint.setColor(Color.RED); 
paint.setStyle(Paint.Style.FILL_AND_STROKE); 
paint.setDither(false); 
paint.setStrokeWidth(3); 
paint.setAntiAlias(true); 

for (int i = 0; i < length; i++) { 
    Path path = new Path(); 
    path.moveTo(a, b); 
    path.lineTo(c, d); 
    path.moveTo(c, d); 
    path.lineTo(e, f); 
    canvas.drawPath(path, paint); 
} 
+0

什么。 – blessenm

+0

您是否尝试过在您的Paint对象上设置消除锯齿? – Bringer128

+0

是的,我编辑了我的问题。 –

回答

82

也许这将创建要

paint.setColor(color);     // set the color 
paint.setStrokeWidth(size);    // set the size 
paint.setDither(true);     // set the dither to true 
paint.setStyle(Paint.Style.STROKE);  // set to STOKE 
paint.setStrokeJoin(Paint.Join.ROUND); // set the join to round you want 
paint.setStrokeCap(Paint.Cap.ROUND);  // set the paint cap to round too 
paint.setPathEffect(new CornerPathEffect(10)); // set the path effect when they join. 
paint.setAntiAlias(true);       // set anti alias so it smooths 

:)你需要把你的代码改写

+0

确认正在工作。谢谢! –

+0

谢谢你,你救了我的一天。 –

11

你可能不想lineTo(c, d),然后立即moveTo(c, d)这是相同点。如果你这样做,你不会在两条线段上获得一个不错的角落连接,这可能看起来像一个丑陋的差距。

尝试删除那个moveTo

+0

非常好的提示。 –