How to draw a curved line between 2 points on canvas?

前端 未结 3 851
借酒劲吻你
借酒劲吻你 2021-01-02 17:14

I have tried a lot of different approaches from examples around the web, but I can\'t seem to get this to work. I am trying to make a method that draws a curved line between

3条回答
  •  忘掉有多难
    2021-01-02 17:53

    Suppose you have two points mPoint1 and mPoint2

    int w=canvas.getWidth();
    int h=canvas.getHeight();
    int w_2= (w / 2);
    int h_2= (h / 2);
    PointF mPoint1 = new PointF(0, 0); //starts at canvas left top
    PointF mPoint2 = new PointF(w_2, h_2);//mid of the canvas
    Path drawPath1 =drawCurve(mPoint1, mPoint2);
    canvas.drawPath(drawPath1, paint);
    

    Method to draw the line

    private Path drawCurve(PointF mPointa, PointF mPointb) {
                Path myPath = new Path();
                myPath.moveTo(mPointa.x, mPointa.y);
                final float x2 = (mPointb.x + mPointa.x) / 3;
                final float y2 = (mPointb.y + mPointa.y) / 3;
                myPath.quadTo(x2, y2, mPointb.x, mPointb.y);
                return myPath;
    }
    

提交回复
热议问题