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.
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|
|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|
|Video and Audio||Requires a player like Windows Media Player||Built-in support|
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.
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.
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.
Images created in GDI/GDI+ are pixel-based, raster images. Those created in WPF can be scalable, vector images.
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.
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.
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.
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 is an important part of painting with GDI or GDI+. In WPF, it is not considered.
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
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.
As a framework, WPF enables you to use:
Medical Web Viewer .NET
.NET, Java, Android, and iOS/macOS Assemblies
C API/C++ Class Libraries