使用 GDI+
System.Drawing 主命名空间
System.Drawing.Design 扩展设计时用户接口的类
System.Drawing.2D 高级可视效果的类
System.Drawing.Imaging 高级图像文件操作的类
System.Drawing.Printing 打印功能
System.Drawing.Text 字体操作
Graphics对象
System.Drawing.Graphics myGraphics;
myGraphics = myForm.CreateGraphics();
Bitmap myImage = new Bitmap("C:\\myImage.bmp");
myGraphics = Graphics.FromImage(myImage);
坐标 System.Drawing
Point
PointF
Size
SizeF
Rectangle
RectangleF
例:矩形
Point myOrigin = new Point(10,10);//起始点
Size mySize = new Size(20,20);
Rectangle myRect = new Rectangle(myOrigin,mySize);
绘图形状
DrawArc 弧
DrawBezier 贝塞尔
DrawBeziers 一系列贝塞尔样条
DrawClosedCurve 闭合曲线
DrawCurve 开放曲线
DrawEllipse 椭圆
DrawLine 线
DrawLines 一系列线条
DrawPath 复杂形状的路径对象
DrawPie 扇形
DrawPolygon 多边形
DrawRectangle 矩形
DrawRectangles 一系列矩形
实心形状
FillClosedCurve 实心闭合曲线
FillEllipse 实心椭圆
FillPath 复杂实心
FillPie 实心扇形
FillPolygon 实心多边形
FillRectangle 实心矩形
FillRectangles 一系列实心矩形
FillRegion 实心复杂形状
颜色
Color.FromArgb(Red,Green,Blue,Alpha) Alpha可以省略
或已定义颜色
Color.Tomato;
SystemColors.HighlightText;
画笔
System.Drawing.SolidBrush 单色画笔
System.Drawing.Texture 图像填充画笔
System.Drawing.Drawing2D.HatchBrush 阴影模式
System.Drawing.Drawing2D.LinearGradientBrush 渐变
System.Drawing.Drawing2D.PathGradientBrush 复杂渐变
笔,用来绘制线
Pen myPen=new Pen(Color.Lime,4);
或
new Pen(myBrush);
复杂形状
GraphicsPath myPath = new Drawing2D.GraphicsPath();
或
new GraphicsPath(new Point[] {new Point(1,1),new Point(32,54),new Point(33,5)},
new byte[] {(byte)PathPointType.Start,(byte)PathPointType.Line,(byte)PathPointType.Bezier});
将图形添加到路径 Addxxx
myPath.StartFigure();
//添加
myPath.CloseFigure();