Skip to content Skip to sidebar Skip to footer

Andorid Drawpath Doesn't Fill-up The Enclosed Area

Following list shows the x,y coordinates and particular method used to create a Path. 0 0 moveTO 180 0 lineTo 180 0 moveTO 246 227, 127 24, 115 150 cub

Solution 1:

Please post your actual code. It's unclear from your formatting if you're calling moveTo or lineTo after arriving at the set of points or before.

EDIT:

The moveTo calls are unnecessary, the lineTo and cubicTo calls already move you to the new point.

Your code:

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    paint.setColor(Color.RED);
    paint.setStyle(Paint.Style.FILL);

    p.moveTo(0, 0);
    p.lineTo(180, 0);
    p.moveTo(180, 0);
    p.cubicTo(246, 227, 127, 24, 115, 150);
    p.cubicTo(127, 276, 246, 71, 180, 300);
    p.moveTo(180, 300);
    p.cubicTo(44, 261, 166, 332, 90, 339);
    p.cubicTo(14, 332, 136, 261, 0, 300);
    p.moveTo(0, 300);
    p.lineTo(0, 0);

    canvas.drawPath(p, paint);
}

produced this:

image with drawing error

Removing the moveTo calls (and using close() instead of lineTo(0,0)):

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    paint.setColor(Color.RED);
    paint.setStyle(Paint.Style.FILL);

    p.lineTo(180, 0);
    p.cubicTo(246, 227, 127, 24, 115, 150);
    p.cubicTo(127, 276, 246, 71, 180, 300);
    p.cubicTo(44, 261, 166, 332, 90, 339);
    p.cubicTo(14, 332, 136, 261, 0, 300);
    p.close();

    canvas.drawPath(p, paint);
}

produced this:

fixed image

Post a Comment for "Andorid Drawpath Doesn't Fill-up The Enclosed Area"