GDI+是.net引入的绘图类,相对于GDI绘图来说,使用更简单,功能更强大。
补充一点:实际上GDI以及GDI+技术winxos很早前就用过了,只是一直不知道这个叫GDI+。。。
下面我用C#写了个简单的GDI+使用示例,相应的.NET其他语言(如VB.NET ,VC.NET)的代码基本一样。
程序代码如下:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Drawing.Drawing2D; /* *GDI+绘图演示,编程环境为vs2008 + C# *一直没注意过GDI以及GDI+,原来以前常用的绘图就是用的GDI以及GDI+, *例如我们用VC6中的MFC中的绘图,实际上就是用的GDI,而.net中采用的Graphics就是用的GDI+, *当然GDI+的优势比较明显,语法简单,代码短,容易理解,显示效果好,功能强大许多。 *使用GDI+进行绘图操作还是比较简单的,如果有兴趣的朋友不妨看看相关的书籍。 *详细了解的话,推荐大家看 Graphics Programming with GDI+ ,中文版名字叫GDI+图形程序设计,作者Mahesh Chand *winxos 2009-6-15 */ namespace gdi_ { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; g.SmoothingMode = SmoothingMode.AntiAlias; PointF x1 = new PointF(10F, 10F); //PointF与Point的区别在于参数为浮点数 Point x2 = new Point(100, 100); Pen p = new Pen(Color.Red,4); Brush b = Brushes.Blue; Font f = new Font("Verdana", 10);
StringFormat sf = new StringFormat(); sf.FormatFlags = StringFormatFlags.DirectionVertical; //垂直显示文本 g.DrawLine(p, x1, x2);
g.RotateTransform(30f, MatrixOrder.Prepend); //整个图形对象旋转 g.DrawString ("Hello winxos!",f ,b,x1); g.RotateTransform(-60f, MatrixOrder.Append ); g.TranslateTransform(-80, 0); g.DrawString("WINXOS!", f, b, x2, sf); LinearGradientBrush lgb = //一个线性渐变颜色 new LinearGradientBrush ( new Rectangle (10,10,50,50), Color.Green, Color.Blue, LinearGradientMode.Horizontal ); g.FillRectangle(lgb,150,150,200,200); g.Dispose(); }
private void Form1_Load(object sender, EventArgs e) { } } }
|
winxos 2009-06-15 17:54
转载于:https://blog.51cto.com/winxos/330883