7.1.1 GDI + Overview
GDI + is the new graphics device interface that Microsoft provides in the operating system after Windows 2000, which is presented through a set of classes that are deployed as managed code.
This class is referred to as the "managed class interface" of GDI +, and GDI + provides the following three types of services:
(1) Two-dimensional vector graphics: GDI + provides classes (or structs) that store the information of the graphical primitives themselves, classes that store information about how the graphics primitives are plotted, and classes that are actually drawn.
(2) Image processing: Most images are difficult to delimit as a set of lines and curves, and cannot be processed using two-dimensional vector graphics.
As a result, GDI + provides us with classes such as bitmap, image, etc., which can be used to display, manipulate, and save image formats such as BMP, JPG, GIF, and so on.
(3) Text display: GDI + supports displaying text using a variety of fonts, sizes, and styles.
We have to do graphical programming, we must first explain the graphics class, and we must also master pen, brush and rectangle these kinds.
Common classes and structures:
Graphics drawing
Pen is used to populate with patterns, colors, or bitmaps.
Color colors
Font is used to format text.
Brush is used to describe colors.
Rectangle rectangular structures are typically used to draw rectangles on a form.
The point describes a pair of ordered X, y two coordinate values.
Namespaces:
Using System.Drawing;
Using System.Drawing.Drawing2D;
Using System.Drawing.Imaging;
Graphics class (picture drawing)
3 ways to create a Graphics object
1. The first type of Paineventargs in the paint event of a control or form
Response method for the form's Paint event
private void Form1_paint (object sender, PaintEventArgs e)
{
Graphics g = e.graphics;
}
You can also overload the OnPaint method of a control or form directly, as shown in the following code:
protected override void OnPaint (PaintEventArgs e)
{
Graphics g = e.graphics;
}
2. Call the CreateGraphics method of a control or form
Invokes the CreateGraphics method of a control or form to obtain a reference to a Graphics object that represents the drawing surface of the control or form.
This method is typically used if you want to draw on a form or control that already exists.
For example:
Graphics g = this. CreateGraphics ();
3. Calling the FromImage static method of the Graphics class
Creates a graphics object from any object inherited from image. This method is typically used when you need to change an image that already exists.
For example:
Image img = image.fromfile ("g1.jpg");//Creating an Image Object
Graphics g = Graphics.fromimage (IMG);//Create a Graphics object
Methods for graphics objects
DrawArc to draw an arc.
DrawBezier draw three-dimensional belser curve.
DrawBeziers draw the Belser curve of continuous stereoscopic.
DrawClosedCurve draw a closed curve.
DrawCurve draw curves.
DrawEllipse draws an ellipse.
DrawImage to draw images.
DrawLine draw lines.
DrawPath lines and curves are drawn through the path.
Drawpie appeased shape.
DrawPolygon draw polygons.
DrawRectangle draw a rectangle.
DrawString draw text.
FillEllipse fills the ellipse.
FillPath the fill path.
FillPie fills the pie chart.
FillPolygon fills the polygon.
FillRectangle fills the rectangle.
Fillrectangles fills a rectangular group.
FillRegion fills the area.
Color structure
Common Properties
A gets the alpha transparency component value, which is the value (0~255).
B Gets the blue component value, which is the value (0~255).
G Gets the green component value, value (0~255).
R Gets the red component value, which is the value (0~255).
Create a color structure:
Color CLR1 = Color.FromArgb (122,25,255);
Color CLR2 = Color.fromknowcolor (Knowcolor.brown);//knowncolor is an enumeration type
Color CLR3 = Color.fromname ("Slateblue");
GDI + Learning Notes