Article submitted by: Alistair Keys
Umm, GDI You Say?
GDI stands for Graphics Device Interface, and is the interface that Windows uses for drawing 2D graphics. It is also, unfortunately, the slowest method around, but is useful for basic graphics. This tutorial will introduce you to some of the jargon and terms in the GDI.
The first point to note is that you should not attempt to use the GDI for any fancy graphical effects, like cross-fading pictures, as it is a bit primitive. For professional-looking graphics try using DirectX, OpenGL, or a graphics library (e.g. any of these, among others: DelphiX, FastLib, DIBUltra, Graphics32...). However, you can use the GDI for some neat effects, with a little creativity.
Anything Else I Should Know?
One common acronym you will find with GDI is DC ("Device Context"). This is what you draw on, and is represented in Delphi by TCanvas. The idea behind device contexts is to abstract the output device details, so you can use the same drawing functions for (e.g.) a screen or a printer.
Another (pretty important) note is that you will start by using the standard Delphi graphics functions, as these are wrappers for the GDI functions of Windows. When the need arises, I will describe the Windows GDI functions for which Delphi provides a nice interface.
Enough Jargon! Let's Draw!
Patience, my friend. You will be drawing pretty pictures soon enough. First, you need to know a little about how the GDI is organized. Here are some classes of importance:
| NAME |
DESCRIPTION |
| Pen |
This is used to draw simple lines. Examples are the LineTo function, or drawing the border for some shapes (e.g. the function Rectangle). |
| Brush |
A brush is used to fill areas with color. Examples are the functions Rectangle, FillRect or FloodFill. |
| Font |
Intuitively, this is just the font to use for any text drawing you need. You can specify font name, size, etc. |
| Region |
A region is Windows-speak for an enclosed space. This could mean a circle, square, dodecahedron, or anything. It can have holes in the shape, too. |
Now you've experienced some silly jargon we can start to draw things. We'll take it easy and begin with lines and shapes.
Question, Suggestions...
If you have any questions or comments to this (huge) article, please post them on the Delphi Programming Forum. Discuss!
Next page > Drawing lines > Page 1, 2, 3, 4, 5, 6, 7, 8, 9