3.使用GDI+画曲线

     来源:http://www.cnblogs.com/kiny/articles/2506700.html

1.画贝塞尔曲线

DrawBezier(Pen pen, Point pt1, Point pt2, Point pt3, Point pt4)
DrawBezier(Pen pen, PointF pt1, PointF pt2, PointF pt3, PointF pt4)
DrawBezier(Pen pen, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
DrawBeziers(Pen pen, Point[] points)
DrawBeziers(Pen pen, PointF[] points)
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            //创建画板从Paint事件中的直接引用Graphics对象
            Graphics graphics = e.Graphics;
            graphics.Clear(Color.Black);

            //定义画笔
            Pen pen = new Pen(Color.White, 3.0f);

            Point p1 = new Point(100, 100);
            Point p2 = new Point(200, 400);
            Point p3 = new Point(400, 400);
            Point p4 = new Point(500, 100);

            graphics.DrawBezier(pen, p1, p2, p3, p4);
        }

3.使用GDI+画曲线_第1张图片

2. 绘制曲线

        DrawCurve(Pen pen, Point[] points)
        DrawCurve(Pen pen, PointF[] points)
        
        //tension:大于或等于 0.0F 的值,该值指定曲线的张力。
        DrawCurve(Pen pen, Point[] points, float tension)
        DrawCurve(Pen pen, PointF[] points, float tension)

        //offset:从 points 参数数组中的第一个元素到曲线中起始点的偏移量。
        //numberOfSegments: 起始点之后要包含在曲线中的段数。
        DrawCurve(Pen pen, PointF[] points, int offset, int numberOfSegments)
        DrawCurve(Pen pen, Point[] points, int offset, int numberOfSegments, float tension)
        DrawCurve(Pen pen, PointF[] points, int offset, int numberOfSegments, float tension)
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            //创建画板从Paint事件中的直接引用Graphics对象
            Graphics graphics = e.Graphics;
            graphics.Clear(Color.Black);

            //定义画笔
            Pen pen = new Pen(Color.White, 3.0f);

            //定义点坐标
            Point[] points = { 
                         new Point(50,50),
                         new Point(100,25),
                         new Point(200,5),
                         new Point(250,50),
                         new Point(300,100),
                         new Point(350,200),
                         new Point(250,250)
                     };
            graphics.DrawCurve(pen, points, 0.5f);
        }

     第三个参数是张力(平滑度),如果等于0.0的话就是线段了,相当于DrawLines,越接近1.0越光滑。如果大于1.0的出现异常结果。下面是从0.0,1.0的效果图

3.使用GDI+画曲线_第2张图片

3.使用GDI+画曲线_第3张图片

3.画封闭曲线

DrawClosedCurve(Pen pen, Point[] points)
DrawClosedCurve(Pen pen, PointF[] points)

//tension:大于或等于 0.0F 的值,该值指定曲线的张力。
//fillmode:System.Drawing.Drawing2D.FillMode 枚举的成员,它确定填充曲线的方式。需要此参数但被忽略。
DrawClosedCurve(Pen pen, Point[] points, float tension, FillMode fillmode)
DrawClosedCurve(Pen pen, PointF[] points, float tension, FillMode fillmode)
private void Form1_Paint(object sender, PaintEventArgs e)
        {
            //创建画板从Paint事件中的直接引用Graphics对象
            Graphics graphics = e.Graphics;
            graphics.Clear(Color.Black);

            //定义画笔
            Pen pen = new Pen(Color.White, 3.0f);

            //定义点坐标
            Point[] points = { 
                         new Point(50,50),
                         new Point(100,25),
                         new Point(200,5),
                         new Point(250,50),
                         new Point(300,100),
                         new Point(350,200),
                         new Point(250,250)
                     };
            graphics.DrawClosedCurve(pen, points);
        }

3.使用GDI+画曲线_第4张图片

你可能感兴趣的:(3.使用GDI+画曲线)