GDI + Programming Basics (i) GDI + Vs GDI

Source: Internet
Author: User
Tags requires visual studio

This article supporting source code

First, GDI

GDI is located in the middle tier between the application and different hardware, which frees programmers from working directly with different hardware, and gives the difference between hardware to GDI. GDI enables Windows applications to run without hindrance on any graphics output device that Windows supports by isolating applications from the characteristics of different output devices. For example, a program that works on a Epson point printer can work on a laser printer without changing the program. It converts graphics output from a Windows system to a hardware command and sends it to a hardware device. GDI is stored as a file in the system, the system needs to output graphics to load it into memory, if the conversion to hardware commands encountered non-GDI commands, the system may also load hardware drivers, driver auxiliary GDI to convert graphics commands to hardware commands.

Second, the equipment environment

Windows system is a tool used to provide device independence for an application, an internal data structure used by Windows systems to process output devices, a device environment that is a link between a windos program, a driver, and an output device (such as a printer, plotter), and GDI is a group of C + + classes , which, with the help of the driver, depicts the data on the hardware, between the application and the hardware, and the data from one side to the other. In Visual Studio. NET Micro$oft solves many of the problems in GDI and makes it easy to use, and GDI's. NET version is called GDI +.

Third, GDI +

GDI + is the next version of GDI, which is well improved and easier to use. One of the benefits of GDI is that you don't need to know any details about how the data is rendered on the device, and GDI + does this better, that is, GDI is a medium and low level API, you may also want to know the device, and GDI + is a high-level API, you don't have to know the device. For example, if you want to set the foreground and background color of a control, simply set the BackColor and ForeColor properties.

Iv. changes in programming patterns

"GDI uses a stateful model, whereas GDI + uses a stateless"--gdi is stateful, GDI + is stateless.

1, no longer use the device environment or handle

When you use GDI drawings, you must specify a device environment (DC) that associates a window or device with a handle pointer to the device environment class, and all drawing operations are related to that handle. GDI + no longer uses this device environment or handle, replacing it with a graphics object. Similar to the device environment, the graphics object is also associated with one window of the screen and contains the related attributes required by the drawing operation. However, only this graphics object is associated with the device environment handle, and the rest of the objects such as pen, Brush, image, and font are no longer using the device environment.

2, Pen, Brush,font,image and other objects are graphic objects Independent

Brush objects can be created in maintenance separately from the drawing objects that are used to provide the drawing method, and the graphics drawing method directly takes the pen object as its own parameter, thus avoiding the tedious switching of the GDI using SelectObject, similar to brush, Path, Image and font and so on.

3, "Current position"

There is always a special location called current position in GDI drawing operations, such as drawing lines. Each line is based on this current position as the starting point, after the line is finished, the end point position of the line becomes the current position. The reason for setting the current position is to improve the efficiency of line operation, because in some cases, a straight line is always attached to the other line. With Automatic Updates to the current position, you can avoid the two-point coordinates each time you draw a line. While it is necessary to draw a straight line alone, there is always a lot of time, so GDI + cancels this "current position" to avoid drawing errors when the "current position" cannot be determined, instead of specifying the coordinates of the starting and ending points of the line directly in the DrawLine.

4. Drawing and filling

GDI always makes shape outlines draw and fill using the same drawing function, such as rectangle. Contour drawing requires a brush, while filling an area requires a brush. That is, regardless of whether we need to populate the drawn shape, we need to specify a brush, otherwise the GDI will be filled with the default brush. This approach does bring us a lot of inconvenience, and now GDI + uses different methods to separate shape contour drawing and fill operations, for example, DrawRectangle and FillRectangle are used to draw and populate a rectangle, respectively.

5, the operation of the area

GDI provides a number of zone creation functions, such as CreateRectRgn, Createellpticrgn, CreateRoundRectRgn, CreatePolygonRgn, and CreatePolyPolygonRgn. Admittedly, these functions bring us a lot of convenience. However, in GDI +, as a way to facilitate the introduction of a matrix transformation operation, GDI + simplifies the method of general area creation and makes the more complex area creation to the path takeover. Because the path object is separate from the device environment, it can be specified directly in the region constructor.

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.