第7章c图形程序设计基础内容摘要:

h( , , , )。 ( myBrush, )。 } 24 如果创建应用程序后向设计窗体上拖放一些控件,可以看到运行后该图就是一个漂亮的背景了。 25 (5)使用 PathGradientBrush类实现彩色渐变 在 GDI+中 , 把一个或多个图形组成的形体称作路径。 可以 使用 GraphicsPath类定义路径 , 使用 PathGradientBrush类定 义路径内部的渐变色画笔。 渐变色从路径内部的中心点逐渐过 渡到路径的外边界边缘。 PathGradientBrush类有三种形式的构造函数 , 形式之一是: public PathGradientBrush( GraphicsPath path ) 其中 , GraphicsPath定义画笔填充的区域。 例 ,路径和路径画笔的使用 : using。 …… 26 private void Form1_Paint(object sender, e) { Graphics g =。 Point centerPoint = new Point(150,100)。 int R=60。 GraphicsPath path=new GraphicsPath()。 (,2*R,2*R)。 PathGradientBrush brush=new PathGradientBrush(path)。 //指定路径中心点 =centerPoint。 //指定路径中心点的颜色 =。 //Color类型的数组指定与路径上每个顶点对应的颜色 =new Color[]{ }。 27 (brush, 2*R,2*R)。 centerPoint=new Point(350,100)。 R=20。 path=new GraphicsPath()。 ( ,2*R,2*R)。 ( *R,*R, 4*R,4*R)。 (*R,*R, 6*R,6*R)。 brush=new PathGradientBrush(path)。 =centerPoint。 =。 =new Color[]{ , }。 (brush,path)。 } 28 在这个例子中,可以看到当使用 FillPath()方法填充路径的时候,如果多个图形互相重叠,则重叠部分的数目为偶数时不会被填充,因此右图中间部分仍为背景色而不是蓝色。 29 附 :平移、旋转与缩放 Graphics类提供了三种对图像进行几何变换的方法 , 它们 是 TranslateTransform()方法 、 RotateTransform()方法和 ScaleTransform()方法 , 分别用于图形图像的平移 、 旋转和 缩放 ( 以坐标系原点为中心 )。 TranslateTransform( )方法的形式为: public void TranslateTransform(float dx,float dy) 其中 , dx表示平移的 x分量 , dy表示平移的 y分量。 RotateTransform( )方法的形式为: public void RotateTransform(float angle) 其中 , angle表示旋转角度。 ScaleTransform( )方法的形式为: public void ScaleTransform(float sx,float sy) 其中, sx表示 x方向的缩放比例, sy表示 y方向的缩放比例。 30 例:三种变换方法示例。 private void Form1_Paint(object sender, e) { Graphics g =。 (new SolidBrush(( 80, )), 120,30,200,100)。 //椭圆透明度 80% ()。 //顺时针旋转 30度 (new SolidBrush((80,)), 120,30,200,100)。 //水平方向向右平移 200个像素,垂直方向向上平移 100个像素 (,)。 (new SolidBrush((50,)), 120,30,200,100)。 (,)。 //缩小到一半 (new SolidBrush((100, )), 120,30,200,100)。 } 31 32 基本图形的绘制 1. 画点 VC采用 Point结构和 SetPixel()方法完成画点的功能;其中Point用于图形设计, SetPixel()用于图像处理 Point原型: public struct Point。 使用: public Point p1 = new Point()。 每个点结构有 x和 y两个属性,表示横纵坐标,如: = 30。 = 100。 33 2. 画直线 1) DrawLine方法 public void DrawLine( Pen pen, int x1, int y1,int x2, int y2 )。 或 public void DrawLine( Pen pen, Point pt1, Point pt2 )。 如: Graphics g = ( )。 Pen p1 = new Pen( , 2 )。 Point pt1 = new Point( 40,50)。 Point pt2 = new Point( 220,150)。 ( p1, 10, 20, 40, 50 )。 ( p1, pt1, pt2 )。 2) DrawLines方法 public void DrawLines( Pen pen, Point[ ] pts )。 34 private void Form1_Paint(object sender, e) { Pen pen = new Pen(, 3)。 Point[] points = { new Point( 10, 10), new Point( 10, 100), new Point(200, 50), new Point(250, 120) }。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。