如何在画布上绘制半椭圆形

时间:2012-06-11 12:04:36

标签: android draw paint android-canvas

我试图在画布上画笑脸。 根据0-100之间的整数,嘴需要看起来快乐或不快乐。以下代码描绘了笑脸:

    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

我画嘴的方法做了这样的事情:

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

但嘴巴看起来非常像素化。有谁知道绘制曲线的更好方法(椭圆的一半)?

1 个答案:

答案 0 :(得分:2)

试试这个:

paint.setAntiAlias(true);

如果不能解决问题,请使用:

paint.setPathEffect(new CornerPathEffect(10));

希望这有帮助