Chapter 63 Bitmaps

63.1 About Bitmaps

A bitmap is a powerful graphics tool that is used to create images, manipulate images (scale, scroll, rotate, and paint them), and store those images as files on disk.

The Control Panel is an example of a Windows applet that uses bitmaps. When a user selects wallpaper for the desktop, they actually select a bitmap that Windows uses to paint the desktop background.

The following illustration shows a desktop background painted with a red-brick pattern:

Painting the Desktop Background with a Bitmap

Windows created this pattern by repeatedly drawing a 32-by-32 pixel pattern on the desktop. This pattern is stored as a bitmap in the file redbrick.bmp. The following illustration shows the 32-by-32 pixel pattern as it appeared when viewed with the Image Editor application:

The Red-Brick Pattern

From the user's point of view, a bitmap is a rectangle of pixels. However, from the application developer's perspective, a bitmap is a collection of data structures which specify or contain:

A header that describes the resolution of the device upon which the rectangle of pixels first appeared, the dimensions of the rectangle, the size of the array of bits, and so on

A logical color-palette

An array of bits that define the relationship between pixels in the bitmapped image and entries in the logical color-palette.

The next illustration is based on the developer's perspective of the bitmap found in the file redbrick.bmp; it shows a color palette, a 32-by-32 pixel rectangle, and the array of bits that maps colors from the palette to pixels in the rectangle:

Mapping Color-Palette Indexes to Pixels

In this example, the rectangle of pixels appeared on a VGA display which used a palette of 16 colors. And, a palette with 16 entries requires 4-bit indices. Therefore, the array that maps palette colors to pixel colors is composed of 4-bit entries as well. (For more information about logical color-palettes, see Chapter 70, “Colors and Color Palettes”)

It's important to note that Windows maps indices to pixels beginning with the bottom scanline of the rectangular region and ending with the top.