2011-09-30 6 views
31

Sto creando percorsi e aggiungendo linee multiple in ogni percorso utilizzando path.moveTo(x, y) e path.lineTo(x, y). Quindi canvas.drawPath(path, paint) sta disegnando tutti i percorsi. Ma ci sono 1-2 pixel di spazio tra le linee in alcuni percorsi. Come posso rimuovere questi spazi? Il mio codice è qualcosa di simile:Come disegnare un percorso scorrevole/arrotondato?

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

è necessario inserire il codice in su. – blessenm

+0

Hai provato a impostare l'anti-aliasing sull'oggetto Paint? – Bringer128

+0

Sì, ho modificato la mia domanda. –

risposta

82

Forse questo creerà ciò che si vuole

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

Confermato il funzionamento. Grazie! –

+0

grazie, mi hai salvato la giornata. –

11

Probabilmente non vogliono lineTo(c, d) e poi subito moveTo(c, d) che è lo stesso punto. Se lo fai, non otterrai un bel corner sui due segmenti di linea, che potrebbe sembrare un brutto spazio.

Provare a rimuovere quello moveTo.

+0

suggerimento molto bello. –