日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

GDI+的应用

發(fā)布時間:2025/3/14 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 GDI+的应用 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

在VS中創(chuàng)建窗體

(1)CDI+清除繪畫面

在窗體中寫入代碼:

protected override void OnPaint(PaintEventArgs e){

  Graphics g=e.Graphics;

  g.Clear(Color.Pink);

  g.Dispose();

}

(2)CGD+繪制多邊形

protected override void OnPaint(PaintEventArgs e){

  Graphics g=e.Graphics;

  Point[] points=new Point[]{

          new Point(200,200),

          new Point(230,230),

          new Point(260,300),

          new Point(300,350)

};

  g.DrawPolygon(new Pen(Color.Red),point);

  g.Dispose();

}

(3)GDI+填充顏色

protected override void OnPaint(PaintEventArgs e){

  //簡單填充顏色

  Graphics g=e.Graphics;

  g.FillRectangle(Brushes.Red,new Rectangle(20,20,100,200));

  //漸變顏色填充

  Brush brush=new LinearGradientBrush(new Point(10,10),new Point(10,10),Color.Yellow,Color.White);

  ?g.FillRectangle(brush,new Rectangle(20,20,100,170));  

  g.Dispose();

}

(4)GDI+繪畫路徑

protected override void OnPaint(PaintEventArgs e){

   Graphics g = e.Graphics;
?????? ? ?? Point[] points = new Point[]{
??????? ? ?????? new Point(100,100),
??????? ? ?????? new Point(100,150),
?????? ? ????? new Point(150,200),
????? ? ????? new Point(50,200),
?????? ? ?? };

  GraphicsPath path = new GraphicsPath(

      points,new byte[]{

          (byte)PathPointType.Start,

          (byte)PathPointType.Line,

          (byte)PathPointType.Line,

          (byte)PathPointType.Line 

      );

}

  g.DrawPath(new Pen(Color.Red),path);

  g.Dispose();

}

(4)GDI+繪制字符串

protected override void OnPaint(PaintEventArgs e){

  Graphics g = e.Graphics;

  //普通繪制字符串

  Font font1=new System.Drawing.Font("宋體",30);

  g.DrawingString("ABCD",font1,Brushes.Red,new PointF(30,30));

  //帶格式的字符串

  ?????? Font font2 = new System.Drawing.Font("宋體", 30);
??????????? RectangleF rect = new RectangleF(100,100,100,200);
??????????? g.DrawRectangle(new Pen(Color.Red),new Rectangle(100,100,100,200));
??????????? //字符串格式對象
??????????? StringFormat sf = new StringFormat();
??????????? sf.Alignment = StringAlignment.Center;//在矩形中居中
??????????? sf.LineAlignment = StringAlignment.Center;
??????????? g.DrawString("abcd",font2,Brushes.Red,rect,sf);
??????????? g.Dispose();

}

(5)GDI+紋理繪畫圖片

?protected override void OnPaint(PaintEventArgs e)
??????? {
??????????? Graphics g = e.Graphics;
??????????? Image image = Image.FromFile("圖片路徑");
??????????? //紋理畫筆
??????????? Brush brush = new TextureBrush(image);//刷出來的位置都有image的存在
??????????? g.DrawRectangle(new Pen(Color.Pink),40,40,300,300);
??????????? g.FillRectangle(brush,new Rectangle(40,40,300,300));
??????????? g.Dispose();

??????? }

轉(zhuǎn)載于:https://www.cnblogs.com/ss977/p/3942428.html

總結(jié)

以上是生活随笔為你收集整理的GDI+的应用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。