system.drawing使用小结
system.drawing下面包括:
system.drawing.drawing2d
system.drawing.imaging
system.drawing.printing
system.drawing.designer
system.drawing.text
首先是椭圆的绘制
Brush solidBrush = new SolidBrush(Color.FromArgb(255,255,0,0));
e.Graphics.FillEllipse(solidBrush,0,0,100,60);
矩形的绘制
Pen blackPen = new Pen(Color.Black,3);
int x = 210;
int y = 220;
int width = 200;
int height = 100;
e.Graphics.DrawRectangle(blackPen,x,y,width,height);
图形填充图象
Image image = new Bitmap(@"F:\WindowsExample\WindowsExample\man.gif");
//初始化使用指定的图象填充Brush TextureBrush
Brush tBrush = new TextureBrush(image);
Pen blackPen = new Pen(Color.Black);
e.Graphics.FillRectangle(tBrush,new Rectangle(0,0,200,200));
e.Graphics.DrawRectangle(blackPen,new Rectangle(0,0,200,200));
线性变化的显示
LinearGradientBrush linepen = new LinearGradientBrush(new Point(0, 10), new Point(200, 10), Color.FromArgb(255, 255, 0, 0), Color.FromArgb(255, 0, 0, 255));
e.Graphics.FillRectangle(linepen,0,155,300,20);
区域图像的绘制
Point[] points2 ={ new Point(75,0),new Point(100,50),new Point(150,50),new Point(112,75),new Point(150,150),new Point(75,100),new Point(0,150),new Point(37,75),new Point(0,50),new Point(50,50)};
//用点针构造一个路径
GraphicsPath path = new GraphicsPath();
path.AddLines(points2);
//用路径构造一个线性梯度刷
PathGradientBrush pthBrush = new PathGradientBrush(path);
//在路径的中部设置颜色为红色
pthBrush.CenterColor = Color.FromArgb(255,255,0,0);
Color[] colors =
{ Color.FromArgb(255, 0, 0, 0),
Color.FromArgb(255, 0, 255, 0),
Color.FromArgb(255, 0, 255, 0),
Color.FromArgb(255, 0, 255, 0),
Color.FromArgb(255, 0, 255, 0),
Color.FromArgb(255, 0, 255, 0),
Color.FromArgb(255, 0, 255, 0),
Color.FromArgb(255, 0, 255, 0),
Color.FromArgb(255, 0, 255, 0),
Color.FromArgb(255, 0, 255, 0),};
pthBrush.SurroundColors = colors;
e.Graphics.FillPath(pthBrush,path);
结果为

接下来是文本的绘制
FontFamily fontfamily = new FontFamily("Times New Roman");//字体族
Font font = new Font(fontfamily,24,FontStyle.Bold,GraphicsUnit.Pixel);
//位置(30,10)处显示
PointF pointf = new PointF(390,100);
SolidBrush solidbrush = new SolidBrush(Color.FromArgb(25,88,255));
e.Graphics.DrawString("Hello",font,solidbrush,pointf);
在矩形中显示字符
String MyText = "Draw text in a rectangle by passing a recF to the Drawstring method";
FontFamily font2 = new FontFamily("Arial");
Font font3 = new Font(font2,12,FontStyle.Bold,GraphicsUnit.Point);
Rectangle rect = new Rectangle(30,10,300,150);
SolidBrush brush = new SolidBrush(Color.FromArgb(255,88,255));
e.Graphics.DrawString(MyText,font3,brush,rect);
Pen pen = Pens.Black;
e.Graphics.DrawRectangle(pen,rect);
关于图形的扭转
Graphics graphics = e.Graphics;
Pen pen = new Pen(Color.Red);
graphics.ResetTransform();
graphics.RotateTransform(20);//通用转换
graphics.DrawEllipse(pen, 0, 0, 100, 50);
graphics.PageUnit = GraphicsUnit.Millimeter;//页面的单位转换
graphics.DrawEllipse(pen,0,0,100,50);
以上是一些鄙人学习的一些基本的东西,我会不断的补充的哦!
system.drawing.drawing2d
system.drawing.imaging
system.drawing.printing
system.drawing.designer
system.drawing.text
首先是椭圆的绘制
Brush solidBrush = new SolidBrush(Color.FromArgb(255,255,0,0));
e.Graphics.FillEllipse(solidBrush,0,0,100,60);
Pen blackPen = new Pen(Color.Black,3);
int x = 210;
int y = 220;
int width = 200;
int height = 100;
e.Graphics.DrawRectangle(blackPen,x,y,width,height);
Image image = new Bitmap(@"F:\WindowsExample\WindowsExample\man.gif");
//初始化使用指定的图象填充Brush TextureBrush
Brush tBrush = new TextureBrush(image);
Pen blackPen = new Pen(Color.Black);
e.Graphics.FillRectangle(tBrush,new Rectangle(0,0,200,200));
e.Graphics.DrawRectangle(blackPen,new Rectangle(0,0,200,200));
LinearGradientBrush linepen = new LinearGradientBrush(new Point(0, 10), new Point(200, 10), Color.FromArgb(255, 255, 0, 0), Color.FromArgb(255, 0, 0, 255));
e.Graphics.FillRectangle(linepen,0,155,300,20);
Point[] points2 ={ new Point(75,0),new Point(100,50),new Point(150,50),new Point(112,75),new Point(150,150),new Point(75,100),new Point(0,150),new Point(37,75),new Point(0,50),new Point(50,50)};
//用点针构造一个路径
GraphicsPath path = new GraphicsPath();
path.AddLines(points2);
//用路径构造一个线性梯度刷
PathGradientBrush pthBrush = new PathGradientBrush(path);
//在路径的中部设置颜色为红色
pthBrush.CenterColor = Color.FromArgb(255,255,0,0);
Color[] colors =
{ Color.FromArgb(255, 0, 0, 0),
Color.FromArgb(255, 0, 255, 0),
Color.FromArgb(255, 0, 255, 0),
Color.FromArgb(255, 0, 255, 0),
Color.FromArgb(255, 0, 255, 0),
Color.FromArgb(255, 0, 255, 0),
Color.FromArgb(255, 0, 255, 0),
Color.FromArgb(255, 0, 255, 0),
Color.FromArgb(255, 0, 255, 0),
Color.FromArgb(255, 0, 255, 0),};
pthBrush.SurroundColors = colors;
e.Graphics.FillPath(pthBrush,path);
接下来是文本的绘制
FontFamily fontfamily = new FontFamily("Times New Roman");//字体族
Font font = new Font(fontfamily,24,FontStyle.Bold,GraphicsUnit.Pixel);
//位置(30,10)处显示
PointF pointf = new PointF(390,100);
SolidBrush solidbrush = new SolidBrush(Color.FromArgb(25,88,255));
e.Graphics.DrawString("Hello",font,solidbrush,pointf);
String MyText = "Draw text in a rectangle by passing a recF to the Drawstring method";
FontFamily font2 = new FontFamily("Arial");
Font font3 = new Font(font2,12,FontStyle.Bold,GraphicsUnit.Point);
Rectangle rect = new Rectangle(30,10,300,150);
SolidBrush brush = new SolidBrush(Color.FromArgb(255,88,255));
e.Graphics.DrawString(MyText,font3,brush,rect);
Pen pen = Pens.Black;
e.Graphics.DrawRectangle(pen,rect);
Graphics graphics = e.Graphics;
Pen pen = new Pen(Color.Red);
graphics.ResetTransform();
graphics.RotateTransform(20);//通用转换
graphics.DrawEllipse(pen, 0, 0, 100, 50);
graphics.PageUnit = GraphicsUnit.Millimeter;//页面的单位转换
graphics.DrawEllipse(pen,0,0,100,50);


浙公网安备 33010602011771号