如何:绘制基数样条曲线
基数自由绘制曲线是一条平滑通过一组给定点的曲线。 若要绘制基数自由绘制曲线,请创建一个 Graphics 对象并将点数组的地址传递 DrawCurve 该方法。
绘制钟形基数自由绘制曲线
以下示例绘制一条通过五个指定点的钟形基数自由绘制曲线。 下图显示了该曲线和五个点。
Point[] points = {
new Point(0, 100),
new Point(50, 80),
new Point(100, 20),
new Point(150, 80),
new Point(200, 100)};
Pen pen = new Pen(Color.FromArgb(255, 0, 0, 255));
e.Graphics.DrawCurve(pen, points);
Dim points As Point() = { _
New Point(0, 100), _
New Point(50, 80), _
New Point(100, 20), _
New Point(150, 80), _
New Point(200, 100)}
Dim pen As New Pen(Color.FromArgb(255, 0, 0, 255))
e.Graphics.DrawCurve(pen, points)
绘制闭合基数自由绘制曲线
- 使用 DrawClosedCurve 类的 Graphics 方法绘制闭合基数自由绘制曲线。 在闭合基数自由绘制曲线中,曲线在数组的最后一个点继续,与数组中的第一个点连接。 以下示例绘制了一条通过六个指定点的闭合基数自由绘制曲线。 下图显示了闭合自由绘制曲线以及六个点:
Point[] points = {
new Point(60, 60),
new Point(150, 80),
new Point(200, 40),
new Point(180, 120),
new Point(120, 100),
new Point(80, 160)};
Pen pen = new Pen(Color.FromArgb(255, 0, 0, 255));
e.Graphics.DrawClosedCurve(pen, points);
Dim points As Point() = { _
New Point(60, 60), _
New Point(150, 80), _
New Point(200, 40), _
New Point(180, 120), _
New Point(120, 100), _
New Point(80, 160)}
Dim pen As New Pen(Color.FromArgb(255, 0, 0, 255))
e.Graphics.DrawClosedCurve(pen, points)
更改基数自由绘制曲线的弯曲方式
- 通过将张力参数传递给 DrawCurve 该方法,可以更改基数自由绘制曲线的弯曲方式。 以下示例绘制了三条通过同一组点的基数自由绘制曲线。 下图显示了三条自由绘制曲线及其张力值。 注意,张力为 0 时,点之间用直线连接。
Point[] points = {
new Point(20, 50),
new Point(100, 10),
new Point(200, 100),
new Point(300, 50),
new Point(400, 80)};
Pen pen = new Pen(Color.FromArgb(255, 0, 0, 255));
e.Graphics.DrawCurve(pen, points, 0.0f);
e.Graphics.DrawCurve(pen, points, 0.6f);
e.Graphics.DrawCurve(pen, points, 1.0f);
Dim points As Point() = { _
New Point(20, 50), _
New Point(100, 10), _
New Point(200, 100), _
New Point(300, 50), _
New Point(400, 80)}
Dim pen As New Pen(Color.FromArgb(255, 0, 0, 255))
e.Graphics.DrawCurve(pen, points, 0.0F)
e.Graphics.DrawCurve(pen, points, 0.6F)
e.Graphics.DrawCurve(pen, points, 1.0F)
编译代码
前面的代码示例专用于 Windows 窗体,它们需要 PaintEventArgse
,这是 Paint 事件处理程序的参数。