Luciano
Luciano

Reputation: 2796

How to draw a half oval on a canvas

I'm trying to draw a smiley on a canvas. The mouth needs to look happy or not happy depending of a integer between 0-100. the following code draws the smiley:

    paint.setStyle(Paint.Style.FILL);
    paint.setColor(getColorByIntesity(intesity));
    canvas.drawCircle(23, 23, 20, paint);

    paint.setColor(Color.BLACK);
    canvas.drawCircle(15, 15, 3, paint); //Left eye
    canvas.drawCircle(31, 15, 3, paint); //Right eye

    paint.setStyle(Paint.Style.STROKE); 
    canvas.drawCircle(23, 23, 20, paint);

    if(intesity >= 55)
        canvas.drawArc(getMouthDrawingByIntesity(intesity), 180, 180, false, paint); //Mouth
    else if(intesity < 55)
        canvas.drawArc(getMouthDrawingByIntesity(intesity), 0, 180, false, paint); //Mouth

My method to draw a mouth does something like this atm:

  final RectF oval = new RectF();
    if(intesity < 5){
        oval.set(11, 12, 35, 35);
    } etc..

But the mouth looks really pixellated. Does anyone knows a better way to draw a curved line (halve of a oval)?

Upvotes: 1

Views: 1777

Answers (1)

Zelleriation
Zelleriation

Reputation: 2854

Try this:

paint.setAntiAlias(true);

If that doesn´t do the trick use this:

paint.setPathEffect(new CornerPathEffect(10));

Hope this helps

Upvotes: 2

Related Questions