Go homepage(回首页) Upload pictures (上传图片) Write articles (发文字帖)
The author:(作者)qqpublished in(发表于) 2014/7/11 9:16:37 c#中GDI+图形图像:GDI+中的基数样条使用方法
c#中GDI+图形图像:GDI+中的基数样条使用方法|实例
GDI+中的基数样条基数样条是一连串单独的曲线,这些曲线连接起来形成一条较大的曲线。基数样条由点的数组和张力参数指定,样条平滑地经过数组中的每个点,曲线的陡度上没有尖角和突然的变化。绘制基数样条,需要Graphics对象、Pen对象和Point(或PointF)对象数组。Graphics 类的实例提供了DrawCurve方法用于绘制基数样条,Pen对象存储基数样条的属性(如线宽和颜色等),Point(或PointF)对象数组存储曲线将要经过的点。DrawCurve方法为可重载方法,其常用格式有以下4种。(1)绘制经过一组指定Point结构的基数样条。语法:public void DrawCurve (Pen pen,Point[] points)参数说明如下。pen:Pen对象,它确定曲线的颜色、宽度和高度。points:Point结构数组,这些结构定义样条。(2)使用指定的张力,绘制经过一组指定Point结构的基数样条。语法:public void DrawCurve (Pen pen,Point[] points,float tension)参数说明如下。pen:Pen对象,它确定曲线的颜色、宽度和高度。points:Point结构数组,这些结构定义样条。tension:大于或等于0.0F的值,该值指定曲线的张力。(3)从相对于数组开始位置的偏移量开始,绘制经过一组指定PointF结构的基数样条。语法:public void DrawCurve (Pen pen,PointF[] points,int offset,int numberOfSegments)DrawCurve方法中各参数及说明如表1所示。表1 DrawCurve方法参数及说明(4)使用指定的张力,绘制经过一组指定Point结构的基数样条。语法:public void DrawCurve (Pen pen,Point[] points,Int offset,int numberOfSegments,float tension)DrawCurve方法中各参数及说明如表2所示。表2 DrawCurve方法参数及说明示例绘制基数样条本示例中,当程序运行时,单击【绘制基数样条】按钮,在窗体中使用指定的张力,绘制一条经过指定Point结构的基数样条。示例运行结果如图1所示。图1 绘制基数样条程序代码如下。Form1窗体中,在【绘制基数样条】按钮的Click事件中分别声明Graphics类和Pen类的两个对象,然后实例化6个Point对象,用来作为基数样条的各连接点,声明一个Point结构数组,并将已经实例化的6个Point对象赋值给该数组,最后调用Graphics对象的DrawCurve方法绘制一条经过Point结构的基数样条。【绘制基数样条】按钮的Click事件代码如下:private void button1_Click(object sender, EventArgs e){Graphics graphics = this.CreateGraphics();Pen myPen = new Pen(Color.Blue, 3);Point point1 = new Point(50, 20);Point point2 = new Point(60, 30);Point point3 = new Point(70, 25);Point point4 = new Point(100, 50);Point point5 = new Point(130, 30);Point point6 = new Point(150, 45);Point[] myPoints = { point1, point2, point3, point4, point5, point6 };graphics.DrawCurve(myPen, myPoints, 1.0F);}完整程序代码如下:★ ★★★★Form1.cs窗体代码文件完整程序代码★★★★★using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace _6_06{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){Graphics graphics = this.CreateGraphics();Pen myPen = new Pen(Color.Blue, 3);Point point1 = new Point(50, 20);Point point2 = new Point(60, 30);Point point3 = new Point(70, 25);Point point4 = new Point(100, 50);Point point5 = new Point(130, 30);Point point6 = new Point(150, 45);Point[] myPoints = { point1, point2, point3, point4, point5, point6 };graphics.DrawCurve(myPen, myPoints, 1.0F);
赞