Research on GDI + and graphics programming, and gdi graphics programming

Source: Internet
Author: User

Research on GDI + and graphics programming, and gdi graphics programming

Basic concepts of GDI +

Common objects of GDI +, including creating and using Graphics, Font, Brush, Pen, and other objects

Drawing common images

Color Structure, Point structure, and Rectangle Structure

1. Concept of GDI +

GDI + is an improved product of GDI (graphical Device Interface.

2. Drawing namespace of GDI +

All the user-created GDI + functions are stored in the System. Drawing. d11 dataset. These include System. Drawing, System. Drawing. Text, System. Drawing. Printing, System. Drawing. Imaging, System. Drawing. Drawing2D, System. Drawing. Design, and other namespaces.

Graphics object

(1) Use the PaintEventArgs parameter of the form or control painting event to create a Graphics object.

(2) Use the CreateGraphics method of the form or control

Graphics g = this. CreateGraphics ();

(3) Use the derived class of Image to create a Graphics object. You can use any derived class of Image to generate the corresponding Graphics object. This method is generally applicable to Image Processing in C.

Bitmap B = new Bitmap ("mybmp .bmp ");

Graphics g = Graphics. FromImage (B );

Pen object

There are four types of constructor of the Pen class. The usage is as follows.

(1) create a Pen object of a certain Color: public Pen (Color)

(2) create a Pen object for a Brush style: public Pen (Brush)

(3) create a Pen object with a-Brush style and a corresponding width: public Pen (Brush, float)

(4) create a Pen object of a certain Color and corresponding width: public Pen (Color, float)

Common attributes of a Pen object

(1) Alignment attribute: used to obtain or set the Alignment of the Pen object.

(2) Color attribute: used to obtain or set the Color of the Pen object.

(3) Width attribute: used to obtain or set the Width of the Pen object.

(4) DashStyle attribute: used to obtain or set the dotted line style drawn through this Pen object.

(5) DashCap attribute: used to specify the style of the two ends of the dotted line. It is a value of the DashCap Enumeration type.

(6) StartCap attribute: used to obtain or set the CAP style of the straight line starting point drawn through this Pen object.

(7) EndCap attribute: used to obtain or set the CAP style of the straight line endpoint drawn through this Pen object.

(8) PenType attribute: used to obtain the straight line style drawn with this Pen object.

Font object

Brush object

1. SolidBrush

The SolidBrush class is used to define a single-color Brush. Its constructor is as follows.

Public SolidBrush (Color. Color)

2. HatchBrush

The HatchBrush class constructor has two types:

[Format 1]: public HatchBrush (HatchStyle, Color );

[Format 2]: public HatchBrush (HatchStyle, Color, Color); HatchBrush has three attributes:

(1) BackgroundColor attribute: gets the background color of the HatchBrush object.

(2) ForegroundColor attribute: gets the foreground color of the HatchBrush object.

(3) HatchStyle attribute: gets the shadow style of the HatchBrush object.

3. LinearGradientBrush

The constructor of the LinearGradientBrush class has multiple formats. The most common formats are as follows.

Public LinearGradientBrush (Point1, Point2, Color1, Color2 );

Common Drawing Method

1. draw a straight line

[Format 1]: public void DrawLine (Pen pen, int x1, int y1, int x2, int y2 );

[Format 2]: public void DrawLine (Pen pen, Point pt1, Point pt2 );

2. Draw an ellipse

[Format 1]: public void DrawEllipse (Pen pen, Rectangle rect );

[Format 2]: public void DrawEllipse (Pen pen, int x, int y, int width, int height );

3. Draw an arc

[Format 1]: public void DrawArc (Pen pen, Rectangle rect, float startAngle, float sweepAngle );

[Format 2]: public void DrawArc (Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle );

4. Draw a slice chart

You can use the DrawPie method of the Graphics object to draw a slice chart. A slice chart actually connects the two endpoints of an arc to the center. The format of the DrawPie method is basically the same as that of the DrawArc method.

5. Draw a rectangle

[Format 1]: public void DrawRectangle (Pen pen, Rectangle rect );

[Format 2]: public void DrawRectangle (Pen pen, int x, int y, int width, int height );

6. Draw a bezr Curve

[Format 1]: public void drawbezr (Pen pen, Point pt1, Point pt2, Point pt3, Point pt4 );

[Format 2]: public void drawbezr (Pen pen, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4 );

7. Draw a polygon

[Format 1]: public void DrawPolygon (Pen pen, Point [] points );

[Format 2]: public void DrawPolygon (Pen pen, PointF [] points );

8. Draw a closed curve

[Format 1]: public void DrawClosedCurve (Pen pen, Point [] points );

[Format 2]: public void DrawClosedCurve (Pen pen, Point [] points, float tension, FillMode fillmode );

9. Draw a non-closed curve

[Format]: public void DrawCurve (Pen pen, Point [] points );

10. Draw a path

[Format]: public void DrawPath (Pen pen, GraphicsPath path );

11. Fill in the ellipse

[Format 1]: public void FillEllipse (Brush brush, Rectangle rect );

[Format 2]: public void DrawEllipse (Brush brush, int x, int y, int width, int height );

12. Fill the rectangle

[Format 1]: public void FillRectangle (Brush brush, Rectangle rect );

[Format 2]: public void FillRectangle (Brush brush, int x, int y, int width, int height );

13. Fill in the pie chart

[Format 1]: public void FillPie (Brush brush, Rectangle rect, float startAngle, float sweepAngle)

[Format 2]: public void FillPie (Brush brush, int x, int y, int width, int height, int startAngle, int sweepAngle );


What is the difference between GDI, GDI +, and Visual Programming of VC/MFC?

The image processing of MFC is based on GDI +, which is an enhanced version of GDI. "What else do we need a plus sign"
The. NET support behind the GDI + is much more convenient to use and process images in. NET than that in GDI (the. NET library is really powerful)

How to make the drawing change with the form in the GDI + (C #) Programming

Write a function in the re-painting event.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.