Graphics Device Interface (GDI)
The Graphics Device Interface (GDI) is a core component of the Microsoft Windows operating system that provides applications with a consistent and device-independent way to interact with graphical output devices such as display monitors and printers. GDI handles tasks such as drawing lines, curves, text, and images, as well as managing colors and fonts.
Key Concepts
- Device Context (DC): An object that encapsulates the attributes of a drawing surface and its associated device. Applications use DCs to draw.
- Pens, Brushes, and Fonts: GDI objects used to define the appearance of lines, fills, and text.
- Bitmaps and Metafiles: GDI supports raster (bitmap) and vector (metafile) graphics.
- Coordinate Systems: GDI uses various coordinate systems for drawing and mapping.
Core Functionality
Drawing Primitives
GDI provides functions for drawing basic shapes:
LineTo
,MoveToEx
: Draw lines.Rectangle
,RoundRect
,Ellipse
,Polygon
,Polyline
: Draw rectangles, rounded rectangles, ellipses, polygons, and polylines.
Text and Fonts
Applications can render text using various fonts and styles:
TextOut
,ExtTextOut
: Write text.CreateFont
,CreateFontIndirect
: Create font objects.GetTextMetrics
: Retrieve font metrics.
Image Manipulation
GDI allows for the display and manipulation of bitmap images:
BitBlt
,StretchBlt
: Copy bitmap data between devices.CreateCompatibleBitmap
: Create bitmaps compatible with a device context.
Structures
Structure | Description |
---|---|
POINT |
Specifies the x- and y-coordinates of a point. |
RECT |
Specifies the coordinates of the upper-left and lower-right corners of a rectangle. |
LOGFONT |
Defines the attributes of a font. |
BITMAP |
Contains information about a bitmap. |
Important Notes
Note: While GDI is fundamental, modern Windows graphics development often leverages DirectX for high-performance 2D and 3D graphics. However, GDI remains essential for many UI elements and compatibility.
Tip: Always ensure that GDI objects (pens, brushes, fonts, bitmaps) are properly released using functions like
DeleteObject
when they are no longer needed to prevent resource leaks.