2011-09-30 38 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

非常好的提示。 –