Hopes

          Start Here..

           

          C# GDI+與圖形編程

          C# GDI+與圖形編程

          2011-11-08 13:12 by Mr.Xer, 432 閱讀, 1 評論, 收藏編輯

          GDI+與圖形編程

          GDI+的基本概念

          GDI+的常用對象,包括Graphics、Font、Brush、Pen等對象的創建和使用

          常用圖形的繪制

          Color結構、Point結構和Rectangle結構

           

          1.GDI+的概念

                GDI+是GDI(Graphics Device Interface,圖形設備接口)的改進產品。

          2.GDI+的繪圖命名空間

                用戶所使有的GDI+函數都保存在System.Drawing.d11程序集中。其中包括System.Drawing、System.Drawing.Text、System.Drawing.Printing、System.Drawing.Imaging、System.Drawing.Drawing2D和System.Drawing.Design等命名空間。   

           

           

           

          Graphics對象

          (1)利用窗體或控件的Paint事件的參數PaintEventArgs創建Graphics對象。

          (2)使用窗體或控件的CreateGraphics方法

                 Graphics  g=this.CreateGraphics();

          (3)使用Image的派生類創建Graphics對象。使用Image的任何派生類均可以生成相應的Graphics對象,這種方法一般適用于在C#中對圖像進行處理的場合。

                        Bitmap b=new Bitmap("Mybmp.bmp");

          Graphics g=Graphics.FromImage(b);

           

          Pen對象

          Pen類的構造函數有四種,使用方法如下。

          (1)創建某一顏色的Pen對象:public Pen(Color)

          (2)創建某一刷子樣式的Pen對象:public Pen(Brush)

          (3)創建某—刷子樣式并具有相應寬度的Pen對象:public Pen(Brush,float)

          (4)創建某一顏色和相應寬度的Pen對象:public Pen(Color,float)

          Pen對象的常用屬性

          (1)Alignment屬性:用來獲取或設置此Pen對象的對齊方式。

          (2)Color屬性:用來獲取或設置此Pen對象的顏色。

          (3)Width屬性:用來獲取或設置此Pen對象的寬度。

          (4)DashStyle屬性:用來獲取或設置通過此Pen對象繪制的虛線的樣式。

          (5)DashCap屬性:用來指定虛線兩端風格,是一個DashCap枚舉型的值。

          (6)StartCap屬性:用來獲取或設置通過此Pen對象繪制的直線起點的帽樣式。

          (7)EndCap屬性:用來獲取或設置通過此Pen對象繪制的直線終點的帽樣式。

          (8)PenType屬性:用來獲取用此Pen對象繪制的直線的樣式。 

           

           

          Font對象


           

           

          Brush對象

          1.SolidBrush畫刷

             SolidBrush類用來定義單一顏色的Brush,其構造函數如下。

             public SolidBrush(Color.Color)

          2.HatchBrush畫刷

                HatchBrush類的構造函數有兩種,分別如下:  

          [格式1]:public HatchBrush(HatchStyle, Color);

          [格式2]:public HatchBrush(HatchStyle, Color, Color); HatchBrush畫刷具有三個屬性,分別如下:

          (1)BackgroundColor屬性:獲取此HatchBrush 對象的背景色。

          (2)ForegroundColor屬性:獲取此HatchBrush 對象的前景色。

          (3)HatchStyle屬性:獲取此HatchBrush 對象的陰影樣式。

          3.LinearGradientBrush畫刷

          LinearGradientBrush類的構造函數有多種格式,最常用的格式如下。

              public LinearGradientBrush(Point1, Point2, Color1, Color2);

           

           

          常用圖形的繪制方法

          1.畫直線

                [格式1]:public void DrawLine(Pen pen,int x1,int y1,int x2,int y2);

                [格式2]:public void DrawLine(Pen pen,Point pt1,Point pt2);

          2.畫橢圓

          [格式1]:public void DrawEllipse( Pen pen, Rectangle rect);

          [格式2]:public void DrawEllipse(Pen pen,int x,int y,int width, int height);

          3.繪制圓弧

          [格式1]:public void DrawArc(Pen pen,Rectangle rect,float startAngle,float sweepAngle);

          [格式2]:public void DrawArc(Pen pen,int x,int y,int width,int height,int startAngle,int sweepAngle);

          4.畫扇形圖

          使用Graphics對象的DrawPie方法可以繪制扇形圖,所謂扇形圖其實就是把一段圓弧的兩個端點與圓心相連。DrawPie方法的格式與DrawArc方法基本一致。

          5.畫矩形

          [格式1]: public void DrawRectangle( Pen pen, Rectangle rect);

          [格式2]:public void DrawRectangle(Pen pen,int x,int y,int width,int height);

          6.畫Bezier曲線

          [格式1]:public void DrawBezier(Pen pen,Point pt1,Point pt2,Point pt3,Point pt4);

          [格式2]:public void DrawBezier(Pen pen,float x1,float y1,float x2,float y2,float x3,float y3,float x4,float y4);

          7.畫多邊形

          [格式1]:public void DrawPolygon(Pen pen,  Point[] points);

          [格式2]:public void DrawPolygon(Pen pen, PointF[] points);

          8.繪制閉合曲線

          [格式1]:public void DrawClosedCurve(Pen pen,Point[] points);

          [格式2]:public void DrawClosedCurve(Pen pen,Point[] points,float tension,FillMode fillmode);

          9.繪制非閉合曲線

          [格式]:public void DrawCurve( Pen pen,Point[] points);

          10.繪制路徑

          [格式]:public void DrawPath(Pen pen,GraphicsPath path);

          11.填充橢圓

          [格式1]:public void FillEllipse(Brush brush, Rectangle rect);

          [格式2]:public void DrawEllipse(Brush brush,int x,int y,int width, int height);

          12.填充矩形

          [格式1]: public void FillRectangle( Brush brush, Rectangle rect);

          [格式2]:public void FillRectangle(Brush brush,int x,int y,int width,int height);

          13.填充餅圖

          [格式1]:public void FillPie(Brush brush,Rectangle rect,float startAngle,float sweepAngle)

          [格式2]:public void FillPie(Brush brush,int x,int y,int width,int height,int startAngle,int sweepAngle);

          分類: C#

          posted on 2012-08-19 14:36 ** 閱讀(499) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          導航

          統計

          公告

          你好!

          常用鏈接

          留言簿(2)

          隨筆檔案

          文章分類

          文章檔案

          新聞檔案

          相冊

          收藏夾

          C#學習

          友情鏈接

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 河间市| 密云县| 上思县| 伊吾县| 姚安县| 普兰店市| 汉阴县| 天台县| 郴州市| 奇台县| 灵石县| 沛县| 古交市| 来安县| 平邑县| 鄢陵县| 阳春市| 湘乡市| 封丘县| 海伦市| 兴城市| 长白| 宁南县| 金湖县| 龙游县| 崇文区| 武宣县| 鄂伦春自治旗| 信丰县| 搜索| 黑河市| 安乡县| 称多县| 玉树县| 舒城县| 洪江市| 余庆县| 米脂县| 望都县| 砀山县| 云霄县|