如何:绘制贝塞尔样条序列

可使用 Graphics 类的 DrawBeziers 方法绘制相连的贝塞尔样条序列。

示例

下面的示例绘制一条由两条相连的贝塞尔样条组成的曲线。 第一条贝塞尔样条的终点是第二条贝塞尔样条的起点。

下面的插图显示相连的样条和这七个点。

贝塞尔样条

        ' Point(10, 100) = start point of first spline
        ' Point(75, 10) = first control point of first spline
        ' Point(80, 50) = second control point of first spline

        ' Point(100, 150) = endpoint of first spline and start point of second spline

        ' Point(125, 80) = first control point of second spline
        ' Point(175, 200) = second control point of second spline
        ' Point(200, 80)} = endpoint of second spline
        Dim p As Point() = { _
               New Point(10, 100), _
               New Point(75, 10), _
               New Point(80, 50), _
               New Point(100, 150), _
               New Point(125, 80), _
               New Point(175, 200), _
               New Point(200, 80)}

        Dim pen As New Pen(Color.Blue)
        e.Graphics.DrawBeziers(pen, p)

        Point[] p = {
           new Point(10, 100),   // start point of first spline
           new Point(75, 10),    // first control point of first spline
           new Point(80, 50),    // second control point of first spline

           new Point(100, 150),  // endpoint of first spline and 
                                 // start point of second spline

           new Point(125, 80),   // first control point of second spline
           new Point(175, 200),  // second control point of second spline
           new Point(200, 80)};  // endpoint of second spline

        Pen pen = new Pen(Color.Blue);
        e.Graphics.DrawBeziers(pen, p);

编译代码

前面的示例是为使用 Windows 窗体而设计的,它需要 Paint 事件处理程序的参数 PaintEventArgs e。

请参见

概念

GDI+ 中的贝塞尔样条

其他资源

Windows 窗体中的图形和绘制

构造并绘制曲线