Graphics programming with GDI +
GDI + basic concepts
The GDI + common object, including creating and using Graphics, Font, Brush, Pen object, etc.
Common graphics rendering
Color structure, Point structure and the structure of Rectangle
1. The concept of GDI +
GDI + is a GDI (Graphics Device Interface, Graphics Device Interface) improve the product.
2. GDI + drawing namespace
Some users have the GDI + function are stored in System.Drawing.d11 assembly. Including System.Drawing, System.Drawing.Text, System.Drawing.Printing, System.Drawing.Imaging, System.Drawing.Drawing2D System.Drawing.Design and other namespaces.
Graphics object
(1) using the parameters PaintEventArgs form or control's Paint event to create a Graphics object.
(2) using the method of a form or control CreateGraphics
Graphics g=this.CreateGraphics();
(3) the use of Image Graphics object of a derived class is created. Using Image Any derived class can be generated corresponding to the Graphics object, this method is generally applicable to the case where the image processing in C #.
Bitmap b=new Bitmap("Mybmp.bmp");
Graphics g=Graphics.FromImage(b);
Pen object
Pen constructor class four, using the following method.
(1) create a Pen object colors: public Pen (Color)
(2) create a brush Pen object style: public Pen (Brush)
(3) Create a - a brush pattern and having a width corresponding Pen object: public Pen (Brush, float)
(4) A Pen object to create a certain color and corresponding width: public Pen (Color, float)
Pen object common attributes
(1) Alignment Attribute: used to obtain or set the alignment for this Pen object.
(2) Color properties: used to obtain or set the color of this Pen object.
(3) Width Attribute: used to obtain or set the width of this Pen object.
(4) DashStyle properties: This used to get or set the broken line drawn Pen object pattern.
(5) DashCap attributes: style specifies the broken line at both ends, a value is DashCap enumerated type.
(6) StartCap properties: used to obtain or set the starting point of a straight line cap style Pen object by this drawing.
(7) EndCap properties: used to obtain or set the end point of line cap style Pen object drawn by this.
(8) PenType properties: This used to obtain a straight line drawn style Pen object.
Font Object
Brush object
1. SolidBrush brush
SolidBrush class used to define a single color Brush, its constructor as follows.
public SolidBrush(Color.Color)
2. HatchBrush brush
HatchBrush class constructor has two, are as follows:
[格式1]:public HatchBrush(HatchStyle, Color);
[Format 2]: public HatchBrush (HatchStyle, Color, Color); HatchBrush brush having three properties are as follows:
(1) BackgroundColor property: Get the background color of this HatchBrush object.
(2) ForegroundColor property: Get HatchBrush foreground color of this object.
(3) HatchStyle property: Get this shadow style HatchBrush object.
3.LinearGradientBrush画刷
LinearGradientBrush class constructor variety of formats, the most common format.
public LinearGradientBrush(Point1, Point2, Color1, Color2);
Drawing method commonly used graphics
1. Draw a straight line
[格式1]:public void DrawLine(Pen pen,int x1,int y1,int x2,int y2);
[格式2]:public void DrawLine(Pen pen,Point pt1,Point pt2);
2. Oval painting
[Format 1]: public void DrawEllipse (Pen pen, Rectangle rect);
[格式2]:public void DrawEllipse(Pen pen,int x,int y,int width, int height);
3. Draw an arc
[格式1]:public void DrawArc(Pen pen,Rectangle rect,float startAngle,float sweepAngle);
[格式2]:public void DrawArc(Pen pen,int x,int y,int width,int height,int startAngle,int sweepAngle);
4. Draw pie charts
Graphics object DrawPie method may draw the pie chart, pie chart, in fact, the so-called segment of a circle and the center of the two end points are connected. Method DrawArc consistent format DrawPie method.
5. Draw a rectangle
[格式1]: public void DrawRectangle( Pen pen, Rectangle rect);
[格式2]:public void DrawRectangle(Pen pen,int x,int y,int width,int height);
6. Bezier curve drawing
[格式1]:public void DrawBezier(Pen pen,Point pt1,Point pt2,Point pt3,Point pt4);
[格式2]:public void DrawBezier(Pen pen,float x1,float y1,float x2,float y2,float x3,float y3,float x4,float y4);
7. Drawing polygons
[格式1]:public void DrawPolygon(Pen pen, Point[] points);
[格式2]:public void DrawPolygon(Pen pen, PointF[] points);
8. Drawing a closed curve
[格式1]:public void DrawClosedCurve(Pen pen,Point[] points);
[格式2]:public void DrawClosedCurve(Pen pen,Point[] points,float tension,FillMode fillmode);
9. Rendering non-closed curve
[格式]:public void DrawCurve( Pen pen,Point[] points);
10. Draw a path
[Format]: public void DrawPath (Pen pen, GraphicsPath path);
11. Filled oval
[格式1]:public void FillEllipse(Brush brush, Rectangle rect);
[格式2]:public void DrawEllipse(Brush brush,int x,int y,int width, int height);
12. Filled rectangle
[格式1]: public void FillRectangle( Brush brush, Rectangle rect);
[格式2]:public void FillRectangle(Brush brush,int x,int y,int width,int height);
13. Pie filling
[格式1]:public void FillPie(Brush brush,Rectangle rect,float startAngle,float sweepAngle)
[格式2]:public void FillPie(Brush brush,int x,int y,int width,int height,int startAngle,int sweepAngle);
Reproduced in: https: //www.cnblogs.com/zhangchenliang/archive/2012/08/25/2656967.html