Get a site

VC++ 6.0 ebook chapter index
Free counters!

Chapter 15

The Device-Independent Bitmap

In the last chapter, we saw how the Windows GDI bitmap object (also known as the device-dependent bitmap, or DDB) is useful for a variety of programming chores. However, I did not demonstrate how to save these bitmaps to disk files or load them back into memory. This is something that was done back in the old days of Windows but is never done today. The DDB is inadequate for the purpose of image interchange because the format of the bitmap bits is highly device-dependent. There is no color table in a DDB that specifies a correspondence between the bitmap bits and color. The DDB makes sense only when it is created and destroyed within the lifetime of a Windows session.

The device-independent bitmap (or DIB) was introduced in Windows 3.0 to provide a sorely needed image file format suitable for interchange. As you may know, other image file formats, such as .GIF or .JPEG, are much more common than DIB files on the Internet. This is mostly because the .GIF and .JPEG formats implement compression schemes that significantly reduce downloading time. Although there is a compression scheme defined for DIBs, it is rarely used. The bitmap bits in most DIBs are almost always uncompressed. This is actually a major advantage if you want to manipulate the bitmap bits in your program. Unlike .GIF and .JPEG files, the DIB is directly supported by the Windows API. If you have a DIB in memory, you can supply pointers to that DIB as arguments to several functions that let you display the DIB or convert it into a DDB.