版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、根本圖形的繪制根本圖形的繪制西源軟件培訓(xùn)中心西源軟件培訓(xùn)中心回想uGDI+為開發(fā)者提供了一組實(shí)現(xiàn)與各種設(shè)備例如監(jiān)視器,打印機(jī)及其它具有圖形化才干但不及涉及這些圖形細(xì)節(jié)的設(shè)備進(jìn)展交互的庫(kù)函數(shù)。u GDI+的本質(zhì)在于,它可以替代開發(fā)人員實(shí)現(xiàn)與例如顯示器及其它外設(shè)的交互;而從開發(fā)者角度來(lái)看,要實(shí)現(xiàn)與這些設(shè)備的直接交互卻是一項(xiàng)艱巨的義務(wù)。目的u掌握GDI+提供的函數(shù)和方法的運(yùn)用u講解一個(gè)實(shí)例程序畫點(diǎn)C#采用Point構(gòu)造和SetPixel方法完成畫點(diǎn)的功能;其中Point用于圖形設(shè)計(jì),SetPixel用于圖像處置Point原型: public struct Point;運(yùn)用: public Point
2、 p1 = new Point;每個(gè)點(diǎn)構(gòu)造有x和y兩個(gè)屬性,表示橫縱坐標(biāo),如:p1.x = 30;p1.y = 100;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
3、 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_Paintobject sender, System.Windows.Forms.PaintEventArgs ePen pen = new PenColor.Black, 3;Point points = new Point 10, 10, new Point 10, 100, new Point
4、200, 50, new Point250, 120 ; e.Graphics.DrawLinespen, points; 效果 畫直線1 public void DrawEllipsePen pen, int x, int y, int width, int height 其中x, y為橢圓外接矩形左上角的坐標(biāo),width定義橢圓的外接矩形的寬度,height定義橢圓外接矩形的高度。2 public void DrawEllipsePen pen, Rectangle rect 其中rect為Rectangle構(gòu)造,用于確定橢圓的外接矩形。畫橢圓public void DrawArc Pen
5、 pen, int x, int y, int width, int height, int startAngle, int sweepAngle 其中x, y為橢圓外接矩形左上角的坐標(biāo),width定義橢圓。 startAngle圓弧起點(diǎn), sweepAngle順時(shí)針畫過(guò)的角度的外接矩形的寬度,height定義橢圓外接矩形的高度。例: Graphics g = this.CreateGraphics ;Pen pen = new PenColor.Red, 2 ;g.Clearthis.BackColor;g.DrawArcpen,0,0,200,300,-60,180;繪制圓弧public
6、void DrawPie Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle 例: Graphics g = this.CreateGraphics ;Pen pen = new PenColor.Red, 2 ;g.Clearthis.BackColor;g.DrawPiepen,60,60,160,160,160,200;DrawPie扇形1 public void DrawRectanglePen pen, int x, int y, int width, int height參數(shù)含意:
7、2 public void DrawRectanglePen pen, Rectangle rect參數(shù)含意:例:private void Form1_Paintobject sender, System.Windows.Forms.PaintEventArgs eGraphics g = e.Graphics;Pen pen = new Pen Color.Black, 3;Rectangle rect = new Rectangle 30, 30, 200, 100;e.Graphics.DrawRectangle pen, rect ;畫矩形3public void DrawRectan
8、gles Pen pen, Rectangle rects 該方法用于繪制多個(gè)矩形。例:p r i v a t e v o i d F o r m 1 _ P a i n t o b j e c t s e n d e r , System.Windows.Forms.PaintEventArgs eGraphics g = e.Graphics;Pen pen = new PenColor.Black, 3;Rectangle rects = new Rectangle 0, 0, 100, 200,new Rectangle100, 200, 250, 50,new Rectangle30
9、0, 0, 50, 100 ;e.Graphics.DrawRectangles pen, rects ; 畫矩形每段貝塞爾曲線都需求四個(gè)點(diǎn),第一個(gè)點(diǎn)是起始點(diǎn),第四個(gè)點(diǎn)是終止點(diǎn),第二個(gè)點(diǎn)和第三個(gè)點(diǎn)控制曲線的外形。運(yùn)用DrawBezier方法繪制一段貝塞爾曲線,運(yùn)用DrawBeziers方法繪制多段貝塞爾曲線。常用方式有:1 public void DrawBezier Pen pen, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4 2 public void DrawBezier P
10、en pen, Point pt1, Point pt2, Point pt3, Point pt4 3 public void DrawBeziers Pen pen, Point points 其中points是Point構(gòu)造的數(shù)組,第一段貝塞爾曲線從點(diǎn)數(shù)組中的第一個(gè)點(diǎn)到第四個(gè)點(diǎn)繪制而成。以后每段曲線只需求三個(gè)點(diǎn):兩個(gè)控制點(diǎn)和一個(gè)終了點(diǎn)。前一段曲線的終了點(diǎn)會(huì)自動(dòng)用作后一段曲線的起始點(diǎn)。 Bezierprivate void Form1_Paintobject sender, PaintEventArgs ePen blackPen = new PenColor.Black, 3;Point
11、 bezierPoints =new Point50, 100,new Point100, 10,new Point150,290,new Point200, 100,new Point250,10,new Point300, 290,new Point350,100 ; e.Graphics.DrawBeziers blackPen, bezierPoints ; 例如public void DrawPolygon Pen pen, Point points ;public void DrawPolygon Pen pen, PointF points ;其中:PointF表示在二維平面中定
12、義點(diǎn)的、浮點(diǎn) x 和 y 坐標(biāo)的有序?qū)?例:畫一個(gè)四邊形private void button_Clickobject sender, System.EventArgs e Graphics g = this.CreateGraphics ; Pen pen = new Pen Color.Red, 2 ; g.Clear this.BackColor ; Point p1 = new Point new Point 10, 120 , new Point 120, 100, new Point 300,180 , new Point 60, 200 ; g.DrawPolygon pen,
13、p1 ;DrawPolygon多邊形 這個(gè)方法用平滑的曲線將各節(jié)點(diǎn)銜接起來(lái),但會(huì)自動(dòng)把首尾節(jié)點(diǎn)銜接起來(lái)構(gòu)成封鎖曲線。public void DrawClosedCurve Pen pen, Point pts ;public void DrawClosedCurve Pen pen, PointF pts ;public void DrawClosedCurve Pen, Point , float, FillMode ;public void DrawClosedCurve Pen, PointF , float, FillMode ; 其中float型參數(shù)指定彎曲強(qiáng)度,該值范圍為0.0f
14、1.0f,超出此范圍會(huì)產(chǎn)生異常,當(dāng)彎曲強(qiáng)度為零時(shí),就是直線,默許張力為0.5。例如:Pen blackPen = new Pen Color.Black ;Point p1 = new Point new Point 10, 120 , new Point 120, 100, new Point 300,180 , new Point 60, 200 ;g.DrawClosedCurve blackPen, p1 ;DrawClosedCurve方法 DrawCurve方法以四個(gè)點(diǎn)畫出一條根本曲線繪制經(jīng)過(guò)一組指定的Point構(gòu)造數(shù)組定義的曲線,最后一個(gè)點(diǎn)與第一個(gè)點(diǎn)間不畫線。public voi
15、d DrawCurve Pen pen, Point pts ;public void DrawCurve Pen pen, PointF pts ;public void DrawCurve Pen, Point , float ;public void DrawCurve Pen, PointF , float ;其中float參數(shù)代表曲線彎曲的強(qiáng)度。例如:private void button_Clickobject sender, System.EventArgs e Graphics g = this.CreateGraphics ; g.Clear this.BackColor ;
16、 Pen blackPen = new Pen Color.Black, 3 ; Point p1 = new Point new Point 10, 120 , new Point 120, 100, new Point 300,180 , new Point 60, 200 ; g.DrawCurve blackPen, p1 ;DrawCurve方法private void Form1_Paintobject sender,PaintEventArgs ePen redPen = new PenColor.Red, 3;Pen greenPen = new PenColor.Green,
17、 3;Point curvePoints = new Point 50, 250,new Point100, 25,new Point200, 250,new Point250, 50,new Point300, 75,new Point350, 200,new Point400, 150;e.Graphics.DrawLinesredPen, curvePoints;e.Graphics.DrawCurvegreenPen, curvePoints; 繪制直線與平滑曲線例如途徑經(jīng)過(guò)組合直線、矩形和簡(jiǎn)單的曲線構(gòu)成的,可經(jīng)過(guò)Graphics類DrawPath方法來(lái)繪制整個(gè)途徑的各個(gè)對(duì)象。publ
18、ic void DrawPath Pen pen, GraphicsPath path ;例如:private void button_Clickobject sender,System.EventArgs e Graphics g = this.CreateGraphics ;GraphicsPath graphPath = new GraphicsPath;graphPath.AddEllipse 0, 0, 200, 100 ;graphPath.AddRectangle new Rectangle 100, 80, 200, 100 ;graphPath.AddBezier 30, 6
19、0, 70, 60, 50, 30, 100, 10 ;Pen blackPen = new Pen Color.Black, 3 ;g.DrawPath blackPen, graphPath ;DrawPath方法該方法用于畫一個(gè)填充橢圓,常用格式有:public void FillEllipse Brush brush, int x, int y, int width, int height ;public void FillEllipse Brush brush, RectangleF rect ;例如:private void button_Clickobject sender,Sy
20、stem.EventArgs e Graphics g = this.CreateGraphics ;g.Clear this.BackColor ;Brush sp = new SolidBrush Color.Red ;g.FillEllipse sp, 80, 90, 200, 100 ;FillEllipse方法該方法用于畫一個(gè)填充矩形,常用格式有:public void FillRectangle Brush brush, int x, int y, int width, int height ;public void FillRectangle Brush brush, Recta
21、ngle rect ;例如:private void button_Clickobject sender,System.EventArgs e Graphics g = this.CreateGraphics ;g.Clear this.BackColor ;Brush sp = new SolidBrush Color.Red ;g.FillRectangle sp, 80, 90, 200, 100 ;FillRectangle方法該方法用于畫一個(gè)填充餅圖,常用格式有:public void FillPie Brush brush, int x, int y, int width, int
22、 height , int startAngle, int sweepAngle ;2 public void FillPie Brush brush, RectangleF rect, float startAngle, float sweepAngle ;例如:private void button_Clickobject sender,System.EventArgs e Graphics g = this.CreateGraphics ;g.Clear this.BackColor ;Brush sp = new SolidBrush Color.Red ;g.FillPie sp,
23、80, 90, 200, 100, -60, 300 ;FillPie方法設(shè)計(jì)一個(gè)簡(jiǎn)單繪圖板,功能類似Windows畫圖工具。功能有: 能由鼠標(biāo)控制繪制直線、矩形、橢圓,曲線,并能控制線條的顏色。 簡(jiǎn)單繪圖板例如程序講解程序界面作成u在Form中拖入pictureBox和button控件,并進(jìn)展合理規(guī)劃。u使界面如下:u在“直線按鈕Click事件中輸入代碼:uPoint p1 = new Point10,10;uPoint p2 = new Point50,50;uGraphics g = this.pictureBox1.CreateGraphics;uPen pen = new PenCo
24、lor.Black,1;ug.DrawLinepen,p1,p2;簡(jiǎn)單繪圖板例如程序講解 1.“直線起點(diǎn)坐標(biāo)獲取:在控件pictureBox1中按下鼠標(biāo)左鍵獲取起點(diǎn)p1X,Y, 在pictureBox1_MouseDown事件中輸入代碼:Point p1 = Point.Empty, p2 = Point.Empty;p1.X = e.X;p1.Y = e.Y;p2.X = 100; p2.Y = 100;Graphics g = this.pictureBox1.CreateGraphics;Pen pen = new PenColor.Black,1;g.DrawLinepen,p1,p2
25、;簡(jiǎn)單繪圖板例如程序講解 2.“直線終點(diǎn)坐標(biāo)獲?。涸诳丶ictureBox1中松開鼠標(biāo)左鍵獲取終點(diǎn)p2X,Y, 在pictureBox1_MouseUp事件中輸入代碼:Point p1 = Point.Empty, p2 = Point.Empty;p1.X = 100; p1.Y = 100;p2.X = e.X;p2.Y = e.Y;Graphics g = this.pictureBox1.CreateGraphics;Pen pen = new PenColor.Black,1;g.DrawLinepen,p1,p2; 3. 對(duì)程序進(jìn)展調(diào)整,使直線的起點(diǎn)和終點(diǎn)都從光標(biāo)獲取。priva
26、te void pictureBox1_MouseDown p1.X = e.X;p1.Y = e.Y;private void pictureBox1_MouseUpp2.X = e.X;p2.Y = e.Y;Graphics g = this.pictureBox1.CreateGraphics;Pen pen = new PenColor.Black,1;g.DrawLinepen,p1,p2; 簡(jiǎn)單繪圖板例如程序講解 4.直線起點(diǎn)確定后,在pictureBox1控件中挪動(dòng)鼠標(biāo)時(shí),使直線可見, 在pictureBox1_MouseMove事件中輸入代碼:先設(shè)置全局bool變量MouseD
27、own,表示鼠標(biāo)左鍵能否按下。ifMouseDown Graphics g = this.pictureBox1.CreateGraphics;Pen pen = new PenColor.White,1; g.DrawLinepen,p1,p2; /去除前一根直線p2.X = e.X;p2.Y = e.Y;pen = new PenColor.Black,1;g.DrawLinepen,p1,p2;g.Dispose; 簡(jiǎn)單繪圖板例如程序講解 5. 挪動(dòng)鼠標(biāo)時(shí),為了原有直線不被去除, 在MouseMove事件重畫原有的圖形,那么必需先在MouseUp事件中保管每個(gè)已畫的圖形特征。 先設(shè)置全局動(dòng)態(tài)數(shù)組和構(gòu)造。 ArrayList addArray = new ArrayList; public struct SharpType public string type; /圖形外形public Point p1, p2;public Color foreColor; /畫筆顏色 public SharpTypestring type, Point p1, Point p2, Color foreColor t
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 課題申報(bào)參考:跨學(xué)科主題教學(xué)活動(dòng)的設(shè)計(jì)與實(shí)踐研究
- 構(gòu)建可持續(xù)發(fā)展的實(shí)驗(yàn)技術(shù)與設(shè)備共享體系
- 嵌入式系統(tǒng)在環(huán)境監(jiān)測(cè)中的應(yīng)用
- 2024年戶外廣告行業(yè)項(xiàng)目投資申請(qǐng)報(bào)告代可行性研究報(bào)告
- 臨時(shí)人員租賃合同
- 2025年浙科版選擇性必修3化學(xué)下冊(cè)月考試卷
- 2025年浙科版選修6地理下冊(cè)階段測(cè)試試卷含答案
- 2025年人教A版九年級(jí)歷史下冊(cè)階段測(cè)試試卷含答案
- 2025年岳麓版八年級(jí)地理下冊(cè)階段測(cè)試試卷含答案
- 2025年滬科版拓展型課程化學(xué)上冊(cè)月考試卷
- 中國(guó)末端執(zhí)行器(靈巧手)行業(yè)市場(chǎng)發(fā)展態(tài)勢(shì)及前景戰(zhàn)略研判報(bào)告
- 北京離婚協(xié)議書(2篇)(2篇)
- 2025中國(guó)聯(lián)通北京市分公司春季校園招聘高頻重點(diǎn)提升(共500題)附帶答案詳解
- Samsung三星SMARTCAMERANX2000(20-50mm)中文說(shuō)明書200
- 2024年藥品質(zhì)量信息管理制度(2篇)
- 2024年安徽省高考地理試卷真題(含答案逐題解析)
- 廣東省廣州市2024年中考數(shù)學(xué)真題試卷(含答案)
- 高中學(xué)校開學(xué)典禮方案
- 內(nèi)審檢查表完整版本
- 3級(jí)人工智能訓(xùn)練師(高級(jí))國(guó)家職業(yè)技能鑒定考試題及答案
- 孤殘兒童護(hù)理員技能鑒定考試題庫(kù)(含答案)
評(píng)論
0/150
提交評(píng)論