Differences Between GDI and WPF

The Windows Presentation Foundation (WPF) API is fundamentally different from the Graphics Device Interface (GDI) and GDI+ APIs, requiring that many aspects of programming be approached in a different way. This topic briefly outlines the major differences in two major areas, including differences as a renderer and as a framework.

Renderer

As a renderer, WPF enables you to use:

The following table summarizes these differences between GDI-based and WPF-based rendering:

Feature GDI/GDI+ (Windows Forms) WPF
DLLs used System.dll
System.Drawing.dll
System.Windows.Forms.dll
WindowsBase.dll
PresentationCore.dll
PresentationFoundation.dll
Windows Many windows One window
Units Device-dependent unit (pixels) Device-independent unit (1/96-inch)
Control positioning Absolute Absolute, Dynamic, Data-bound
Image is formed by Closely spaced rows of dots (bitmap, raster-based) Mathematical equations (vector-based)
Rendering engine DirectShow DirectX (Direct3D) Media Foundation
Mode Immediate - the application repaints the area that becomes invalidated Retained - the application keeps the drawing information and the system does the repainting
Painting Clipping - bounds determined and painting occurs there Rendering performed from back to front - components paint over each other
Pen and brush Current pen and current brush Appropriate pen or brush provided with each drawing call
Painting region Minimize the region to be painted Do not need to minimize
Events Events RoutedEvents
Video and Audio Requires a player like Windows Media Player Built-in support

Windows

Applications built using the GDI/GDI+ API use many windows, and reside under a parent window (MDI). Applications built in WPF have only one window.

Unit of Measure

Applications that use the GDI/GDI+ API use the device-dependent unit (pixel) as the unit of measure. In these applications, as the resolution of the display device increases, the resulting logical image size decreases. Applications built for WPF use the device-independent unit (1/96-inch) as the unit of measure. When the DPI of the device is 96, the two images are equivalent.

Control Positioning

Applications built with GDI+ use absolute positioning. When the parent is resized the child elements do not get resized automatically. Applications built for WPF can use absolute, dynamic, or data-bound positioning. With either absolute or dynamic positioning the controls are positioned relative to the parent element.

Image Basis

Images created in GDI/GDI+ are pixel-based, raster images. Those created in WPF can be scalable, vector images.

Rendering Engine

Both GDI and GDI+ are built upon Win32. GDI is based on the concept of a device context (DC), where applications obtain handles to the device context, and use the handles to interact with the device. GDI+ is a wrapper around GDI that creates a C++ Graphics object. On the other hand, WPF is built upon DirectX, which means it can take advantage of hardware acceleration when performing drawing operations.

Rendering Mode

With GDI and GDI+, rendering uses immediate rendering: the application repaints the area that becomes invalidated. In WPF, rendering uses retained rendering: the application keeps track of the drawing information but the system performs the painting.

Painting

With GDI and GDI+, clipping is used to determine the bounds of the area that has become invalidated and needs to be painted. In WPF, painting is performed from back to front and components paint over each other.

Pens and Brushes

GDI and GDI+ use the concept of a current brush and current pen. In WPF, the brush and pen must be passed with each drawing call.

Paint Region Optimization

Paint region optimization is an important part of painting with GDI or GDI+. In WPF, it is not considered.

Events

GDI and GDI+ use events and event handler delegates using subscription/notification. In contrast, WPF uses bubbling, tunneling, and direct event notification, and the event travels up and down the VisualTree.

Video and Audio

Direct support for video and audio is not provided by GDI or GDI+, but must be obtained through a media player like Windows Media Player. WPF directly supports video and audio via the MediaElement Class.

Framework

As a framework, WPF enables you to use:

Help Version 23.0.2024.3.4
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Imaging, Medical, and Document

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.