有关图形方面的一篇文章,不妨一看

图形

Working with Brushes in GDI+ Drawing GDI+ Objects
The following code draws a line, an ellipse, a curve, and a polygon object. As you can see from the code, I抳e used pen object to fill these objects. See more details.

protected override void OnPaint(PaintEventArgs e)
{
      Graphics g = e.Graphics;
      Pen pn = new Pen(Color.Green, 10);
      g.DrawLine(pn, 100, 10, 30, 10);
      g.DrawEllipse( new Pen(Color.Red, 20), 20, 40, 20, 20);
      g.DrawBezier( new Pen(Color.Blue, 5), new Point(50,60), new      
Point(150,10), new Point(200,230), new Point(100,100) );          
       PointF point1 = new PointF(50.0f, 250.0f);                  
      PointF point2 = new PointF(100.0f, 25.0f);
      PointF point3 = new PointF(150.0f, 5.0f);
      PointF point4 = new PointF(250.0f, 50.0f);
      PointF point5 = new PointF(300.0f, 100.0f);

     PointF[] curvePoints = {point1, point2, point3, point4, point5 };
      g.DrawPolygon(new Pen(Color.Chocolate, 10), curvePoints);
}
  Brush and Brushes Types  
Brush type is an abstract base class. HatchBrush, LinearGradientBrush, PathGradientBrush, SolidBrush and TextureBrush classes are inherited from Brush class. You don抰 use this class directly.
All brush types are defined in System.Drawing and its helper namespaces. Before using brushes, you need to add reference to this namespace. HatchBrush and GradientBrush are defined in System.Drawing.Drawing2D namespace.
You use brushes to fill GDI+ objects with certain kind of brush. You generally call Fill methods of Graphics class to fill various objects such as Ellipse, Arc, or Polygon. There are different kinds of brushes. For example, solid brush, hatch brush, texture brush, and gradient brush.Solid Brushes
Solid brushes are normal brushes with no style. You fill GDI+ object with a color. SolidBrush type is used to work with solid brushes.

Graphics g = e.Graphics;                                    
SolidBrush sdBrush1 = new SolidBrush(Color.Red);                  
SolidBrush sdBrush2 = new SolidBrush(Color.Green);         
SolidBrush sdBrush3 = new SolidBrush(Color.Blue);    
g.FillEllipse(sdBrush2, 20, 40, 60, 70);              
Rectangle rect = new Rectangle(0, 0, 200, 100);            
g.FillPie(sdBrush3, 0, 0, 200, 40, 0.0f, 30.0f );                 
PointF point1 = new PointF(50.0f, 250.0f);                       
PointF point2 = new PointF(100.0f, 25.0f);                  
PointF point3 = new PointF(150.0f, 40.0f);                  
PointF point4 = new PointF(250.0f, 50.0f);                  
PointF point5 = new PointF(300.0f, 100.0f);                             
PointF[] curvePoints = {point1, point2, point3, point4, point5 };    g.FillPolygon(sdBrush1, curvePoints);
The following code draws an ellipse, a pie, and a polygon. 文章,不妨一看-排除妨害案件调研文章">Hatch Brushes
using System.Drawing.Drawing2D;
The hatch brushes are brushes with a hatch style, a foreground color, and a background color. Hatches are a combination of rectangle lines and the area between the lines. The foreground color defines the color of lines; the background color defines the color of area between lines.
HatchStyle defines the hatch styles.

Member Name
BackwardDiagonal
Cross
DarkDownwardDiagonal
DarkHorizontal
DarkUpwardDiagonal
DarkVertical
DashedDownwardDiagonal
DashedHorizontal
DashedUpwardDiagonal
DashedVertical
DiagonalBrick
DiagonalCross
Divot
DottedDiamond
DottedGrid
ForwardDiagonal
The following code shows how to draw hatch brushes.

protected override void OnPaint(PaintEventArgs e)
{
      Graphics g = e.Graphics;
      HatchBrush hBrush1 = new HatchBrush(HatchStyle.DiagonalCross, Color.Chocolate, Color.Red);
      HatchBrush hBrush2 = new HatchBrush(HatchStyle.DashedHorizontal, Color.Green, Color.Black);
      HatchBrush hBrush3 = new HatchBrush(HatchStyle.Weave, Color.BlueViolet, Color.Blue);
      g.FillEllipse(hBrush1, 20, 80, 60, 20);
      Rectangle rect = new Rectangle(0, 0, 200, 100);
      g.FillPie(hBrush3, 0, 0, 200, 40, 0.0f, 30.0f );
      PointF point1 = new PointF(50.0f, 250.0f);                  
      PointF point2 = new PointF(100.0f, 25.0f);
      PointF point3 = new PointF(150.0f, 40.0f);
      PointF point4 = new PointF(250.0f, 50.0f);
      PointF point5 = new PointF(300.0f, 100.0f);
  
      PointF[] curvePoints = {point1, point2, point3, point4, point5 };
      g.FillPolygon(hBrush2, curvePoints);
}
  
And the result looks like following -
Texture Brushes
The texture brushes provides you to use an image as brush and fill GDI+ objects with the brush. The following code use 搈yfile.bmp?as a brush. You need to define an Image object and create brush with that Image and pass the brush into Fill method of GDI+ objects.

private Brush txBrush;

protected override void OnPaint(PaintEventArgs e)
{
      Graphics g = e.Graphics;      
      g.FillRectangle(txBrush, ClientRectangle);
}
private void Form1_Load(object sender, System.EventArgs e)
{
      Image img = new Bitmap(@"C:\myfile.bmp");
      txBrush = new TextureBrush(img);
}
The result looks like following:
Gradient Brushes
Gradient brushes are provides more color to your GDI+ objects. By using LinearGradientBrush type, you can blend two colors together. The following code blends red and green colors.

protected override void OnPaint(PaintEventArgs e)
{
      Graphics g = e.Graphics ;   
      Rectangle rect = new Rectangle(50, 30, 200, 200);   
      LinearGradientBrush lBrush = new LinearGradientBrush(rect, Color.Red, Color.Green,LinearGradientMode.BackwardDiagonal);  
      g.FillRectangle(lBrush, rect);
}
And the result looks like the following:
This like combines blue and green colors -   

LinearGradientBrush lBrush = new LinearGradientBrush(rect, Color.Blue, Color.Green, LinearGradientMode.Vertical);
And the result looks like following:  

时间: 2024-09-16 00:18:02

有关图形方面的一篇文章,不妨一看的相关文章

安防人 这篇文章你能看懂多少?

安防人 这篇文章你能看懂多少? 在互联网技术高速发展的今天,因网络的开放性.隐蔽性.跨地域性等特性,许多安全问题亟待解决,比如在过去的2015年,全球便发生了多起网络安全事件,如美国人事管理局OPM数据泄露,规模达2570万,直接导致主管引咎辞职:英宽带运营商TalkTalk被反复攻击,400余万用户隐私数据终泄露:摩根士丹利35万客户信息涉嫌被员工盗取:日本养老金系统遭网络攻击,上百万份个人信息泄露等. 虽然这些数据我们时常耳闻,但安防行业人士仍然会认为网络安全问题距离我们仍很遥远甚至无关,但

Windows Phone 如果你把Pivot控件当成主页面,那么这篇文章你值得看。

原文:Windows Phone 如果你把Pivot控件当成主页面,那么这篇文章你值得看. 现在很多App都用到了Pivot视图 来当作 整个App主页面.如果你的Pivot视图主页面承载了大量数据的话,你可能会遇到从其他页面返回Pivot主页面时的延迟,过长时间的黑屏导致用户体验很糟糕. 本篇文章,原引自Nokia Dev开发社区所给的建议而测试的一个Demo. 首先怎么组织数据,这个就不说了, 可以从下面图片中看见我放了好多个PivotItem 里面填充了很多数据.   主要是后台: 给Pi

如何用 Caffe 生成对抗样本?这篇文章告诉你一个更高效的算法

Fast Gradient Sign方法 先回顾一下<杂谈CNN:如何通过优化求解输入图像>中通过加噪音生成对抗样本的方法,出自Christian Szegedy的论文<Intriguing properties of neural networks>: 其中n是要求的噪音,是相应的系数,L是x+n属于某个类别的loss,c是某个错误类别的标签.论文中用来得到图像噪声的办法是L-BFGS,这个方法虽然稳定有效,但是很考验算力的,Christian在Google反正机器多又强,用这个

如果看了这篇文章你还不懂傅里叶变换,那就过来掐死我吧(下)

上一篇文章发出来之后,为了掐死我,大家真是很下工夫啊,有拿给姐姐看的,有拿给妹妹看的,还有拿给女朋友看的,就是为了听到一句"完全看不懂啊".幸亏我留了个心眼,不然就真的像标题配图那样了.我的文章题目是,如果看了这篇文章你"还"不懂就过来掐死我,潜台词就是在你学了,但是没学明白的情况下看了还是不懂,才过来掐死我. 另外,想跟很多人抱歉,因为评论太多了,时间有限,不能给每个人回复,还望大家谅解.但是很感谢一直在评论区帮忙解答读者问题的各位,就不一一@了. 这里郑重感谢大

看完这篇文章后,别再说自己不懂用户画像了

用户画像是一个挺新颖的词,最初它是大数据行业言必及之的时髦概念.现在我们运营谈及用户画像,它也是和精准营销.精细化运营直接钩挂的.这篇文章主要讲产品和运营角度的用户画像. 希望看完后,解决你一切关于用户画像的疑问. 什么是用户画像 用户画像一点也不神秘,它是根据用户在互联网留下的种种数据,主动或被动地收集,最后加工成一系列的标签.比如猜用户是男是女,哪里人,工资多少,有没有谈恋爱,喜欢什么,准备剁手购物吗? 我们常把用户标签和用户画像对等.但凡用户画像的文章,类似上文图片都会出现,有用烂的趋势.

文本比较算法Ⅴ——回顾贴,对前面几篇文章的回顾与质疑

文本比较算法Ⅰ--LD算法 文本比较算法Ⅱ--Needleman/Wunsch算法 文本比较算法Ⅲ--计算文本的相似度 文本比较算法Ⅳ--Nakatsu算法 在写了本系列的前面几篇文章之后.有些网友质疑文章的正确性.在仔细的推敲之下,这些网友指正的不无道理.下面举一个反例,来质疑前面文章的正确性. 文本:A:481234781:B:4411327431 先按照LD算法,计算LD矩阵     4 4 1 1 3 2 7 4 3 1   0 1 2 3 4 5 6 7 8 9 10 4 1 0 1

不知道大家对DES有没有兴趣,今天在整理的时候,看到我在一年半前翻译的一篇文章。

如何实现 DES 算法(全). 这是摘自清华BBS的一篇文章,洋文的,小弟把它翻成中文请各位高手指点.分号(:)后的话是小弟的翻译,井号(#)后的是小弟的一点感想.                           How to implement the                      Data Encryption Standard (DES)                         A step by step tutorial                     

微软的这篇文章能彻底解决visual interdev的调试问题(那位仁兄E文好,把她翻译一下)

interdev|visual|解决|微软|问题 微软的这篇文章能彻底解决visual interdev的调试问题需要安装visual interdev server,在visual studio 6.0的第二张盘上 HOWTO: Configure Your Web Server for Visual InterDev 6.0 ASP Debugging ----------------------------------------------------------------------

推荐一篇文章

防止使用者按上一頁按鈕 討論區上常有網友問到這個問題, 如何防止使用者按回上一頁按鈕, 為何會問這一個問題? 應該通常是在防止使用者重複執行一個應用程式, 例如資料庫的新增, 如果使用者按了回上一頁, 有可能會造成重複新增資料, 今天這篇文章就要介紹如何 "盡可能" 的防止使用者按回上一頁 伺服端防止快取 首先來看看伺服端的方法, ASP 的 Response 物件提供了幾個網頁快取 (cache) 相關的屬性, 說明如下 屬性 說明 CacheControl 判斷代理伺服器 (Pro