文档详情

《C#图形程序设计基础》.ppt

发布:2015-10-15约2.06万字共58页下载文档
文本预览下载声明
2 基本图形的绘制 1. 画点 C#采用Point结构和SetPixel()方法完成画点的功能;其中Point用于图形设计,SetPixel()用于图像处理 Point原型: public struct Point; 使用: public Point p1 = new Point(); 每个点结构有x和y两个属性,表示横纵坐标,如: p1.x = 30; p1.y = 100; 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 = this.CreateGraphics( ); Pen p1 = new Pen( Color.Red, 2 ); Point pt1 = new Point( 40,50); Point pt2 = new Point( 220,150); g.DrawLine( p1, 10, 20, 40, 50 ); g.DrawLine( p1, pt1, pt2 ); 2) DrawLines方法 public void DrawLines( Pen pen, Point[ ] pts ); private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { Pen pen = new Pen(Color.Black, 3); Point[] points = { new Point( 10, 10), new Point( 10, 100), new Point(200, 50), new Point(250, 120) }; e.Graphics.DrawLines(pen, points); } 效果 3. 画椭圆 1) public void DrawEllipse(Pen pen, int x, int y, int width, int height) 其中x, y为椭圆外接矩形左上角的坐标,width定义椭圆 的外接矩形的宽度,height定义椭圆外接矩形的高度。 2) public void DrawEllipse(Pen pen, Rectangle rect) 其中rect为Rectangle结构,用于确定椭圆的外接矩形。 4. 绘制圆弧 public void DrawArc( Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle ) 其中x, y为椭圆外接矩形左上角的坐标,width定义椭圆。 startAngle圆弧起点, sweepAngle顺时针画过的角度 的外接矩形的宽度,height定义椭圆外接矩形的高度。例: Graphics g = this.CreateGraphics( ); Pen pen = new Pen(Color.Red, 2 ); g.Clear(this.BackColor); g.DrawArc(pen,0,0,200,300,-60,180); 5. DrawPie(扇形) public void DrawPie( Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle ) 各参数意义: 例: Graphics g = this.CreateGraphics( ); Pen pen = new Pen(Color.Red, 2 ); g.Clear(this.BackColor); g.DrawPie(pen,60,60,160,160,160,200); 6. 画矩形 1) public void DrawRectangle(Pen pen, int x, int y, int width, int height) 参数含意: 2)
显示全部
相似文档