绘制连接三个点的完美曲线

时间:2010-09-28 09:46:58

标签: android

我想绘制一条连接屏幕上三个点的曲线 PointA =(480,46) PointB =(160,137) PointC =(0,228)

如何使用Android API绘制曲线?
请帮助..

谢谢,

1 个答案:

答案 0 :(得分:13)

无论我想要什么,我都可以使用以下代码制作它:

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

    PointF mPoint1 = new PointF(w/1.2F, h/1.2F);
    PointF mPoint2 = new PointF(w/24, h/1.2F);
    Path myPath1 = new Path();
    Paint paint  = new Paint();
    paint.setAntiAlias(true);
    paint.setStyle(Style.STROKE);
    paint.setStrokeWidth(2);
    paint.setColor(Color.WHITE);

    myPath1 = drawCurve(canvas, paint, mPoint1, mPoint2);
    canvas.drawPath(myPath1, paint);

}

private Path drawCurve(Canvas canvas, Paint paint, PointF mPointa, PointF mPointb) {

    Path myPath = new Path();
    myPath.moveTo(63*w/64, h/10);
    myPath.quadTo(mPointa.x, mPointa.y, mPointb.x, mPointb.y);
    return myPath;  
}

这将找到屏幕的两侧(风景模式),并在屏幕上绘制完美的曲线。