Microsoft KB Archive/67883

{|
 * width="100%"|

HOWTO: How to Use a DIB Stored as a Windows Resource

 * }

Q67883

-

The information in this article applies to:


 * Microsoft Windows Software Development Kit (SDK) versions 3.1, 3.0
 * Microsoft Win32 Application Programming Interface (API), used with:
 * Microsoft Windows NT Server versions 3.5, 3.51
 * Microsoft Windows NT Workstation versions 3.5, 3.51
 * Microsoft Windows 95

-

SUMMARY
Device-independent bitmaps (DIBs) are a very useful tool for displaying graphic information in a variety of device environments. With the appropriate device drivers, Windows can display a DIB with varying results on any video display or on a graphics printer.

This article discusses the differences between two methods that can be used to access a DIB from a resource.

MORE INFORMATION
Bitmaps retrieved from resources are very similar to those stored in .BMP files on disk. The header information is the same for each type of bitmap. However, depending upon the method used to retrieve the bitmap from the resource, the bitmap may be a device-independent bitmap (DIB) or a device-dependent bitmap (DDB).

When the LoadBitmap function is used to obtain a bitmap from a resource, the bitmap is converted to a DDB. Typically, the DDB will be selected into a memory device context (DC) and blt'ed to the screen for display.

NOTE: If a 256-color bitmap with a palette is loaded from a resource, some colors will be lost. To display a bitmap with a palette correctly, the palette must be selected into the destination DC before the image is transferred to the DC. LoadBitmap cannot return the palette associated with the bitmap; therefore, this information is lost. Instead, the colors in the bitmap are mapped to colors available in the default system palette, and a bitmap with the system default color depth is returned.

For example, if LoadBitmap loads a 256-color image into an application running on a VGA display, the 256 colors used in the bitmap will be mapped to the 16 available colors, and a 4 bits-per-pixel bitmap will be returned. When the display is a 256-color 8514 unit, the same action will map the 256 bitmap colors into the 20 reserved system colors, and an 8 bits-per-pixel bitmap will be returned.

If, instead of calling LoadBitmap, the application calls FindResource (with RT_BITMAP type), LoadResource, and LockResource, a pointer to a packed DIB will be the result. A packed DIB is a BITMAPINFO structure followed by an array of bytes containing the bitmap bits.

NOTE: If the resource was originally stored as a DDB, the bitmap returned will be in the DDB format. In other words, no conversion is done.

The BITMAPINFO structure is a BITMAPINFOHEADER structure and an array of RGBQUADs that define the colors used in the DIB. The pointer to the packed DIB may be used in the same manner as a bitmap read from disk.

NOTE: The BITMAPFILEHEADER structure is NOT present in the packed DIB; however, it is present in a DIB read from disk.