四、封闭曲线
使用DrawLines()、DrawBezier()或 DrawBeziers()方法将得到一条或一系列有起点有终点的直线或曲线,GDI+也允许绘制一系列的线段,但是最后的线段的终点和第一条线段的起点是连接在一起的,形成了一个封闭的图形。为了绘制这种图形,可以使用Graphics::DrawClosedCurve()方法,该方法重载了四个版本,其中的两个版本语法如下:
public: void DrawClosedCurve(Pen *pen, Point points[]); public: void DrawClosedCurve(Pen *pen, PointF points[]); | 这两个版本非常容易使用,它们允许你提供4个Point 或PointF值的数组,在执行过程中,每一种版本都将绘制一条曲线,穿过每一个点,并连接终点和起点,这里有个例子:
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { Pen *penCurrent = new Pen(Color::Blue); Point pt[] = { Point(40, 42), Point(188, 246), Point(484, 192), Point(350, 48) }; e->Graphics->DrawClosedCurve(penCurrent, pt); } | 代码运行效果如下图:
 图二十八、代码运行效果图 | 上两个版本用来绘制线条,但对线条进行弯曲处理以使图形看起来平滑,如果需要的话,可以画直线来连接各点,而不必进行弯曲处理。基于这种假定,上面的形状将显示如下:
 图二十九、直线连接的封闭图形 | 为了绘制这种类型的图形,需要使用ClosedCurve()方法,可以使用以下版本:
public: void DrawClosedCurve(Pen *pen, Point points[], float tension, FillMode fillmode); public: void DrawClosedCurve(Pen *pen, PointF points[], float tension, FillMode fillmode); | 这些版本可以规定张力大小及填充模式,张力系数使你可以定义曲线的实际形状,如果这个值是零的话,各个点将用直线进行互联。填充模式因数用来定义内部的曲线如何来填充,这由FillMode枚举来进行控制,它定义在System::Drawing::Drawing2D命名空间中。枚举FillMode有两个值,Alternate 和Winding,这里有一个例子:
private: System::Void Form1_Paint(System::Object * sender, System::Windows::Forms::PaintEventArgs * e) { using namespace System::Drawing::Drawing2D; Pen *penCurrent = new Pen(Color::Red); Point pt[] = { Point(40, 42), Point(188, 246), Point(484, 192), Point(350, 48) }; e->Graphics->DrawClosedCurve(penCurrent, pt, 0.75F, FillMode::Winding); } | 这将产生影响如下效果图:
 图三十、代码运行效果图 |
|
|