Multiple Images

4/8/2010

An alternative to scaling is using multiple images, each authored for a different DPI. This technique yields the best results.

The .ico format is already capable of storing multiple image sizes in a single file. When you load the icon or cursor, the application asks for the size that the GetSystemMetrics function suggests; the system then picks the closest image.

The following code example shows how to select from multiple images that are not in .ico format. To be completely DPI aware, an application should still scale the loaded bitmap based on the actual DPI of the device, because it should make no assumption about what DPI resolutions are available.

if (GetDeviceCaps(hdc, LOGPIXELSX) < 130)
   bitmap = LoadBitmap(hInstance, (char*) IDB_BITMAP1);
else
   bitmap = LoadBitmap(hInstance, (char*) IDB_BITMAP2);

When the loaded bitmap is already authored for the correct DPI, scaling it will have no adverse effect on performance or image quality.

See Also

Concepts

Developing DPI Aware Applications
High DPI Display