Bitmaps and metafiles represent two very different ways of storing pictorial information. A bitmap is a complete digital representation of a picture. Each pixel in the image corresponds to one or more bits in the bitmap. Monochrome bitmaps require only one bit per pixel; color bitmaps require additional bits to indicate the color of each pixel.
A metafile, on the other hand, stores pictorial information as a series of records that correspond directly to GDI calls, such as MoveTo, Rectangle, TextOut, and others that you encountered in Chapter 12. A metafile is thus a description of a picture rather than a digital representation of it.
Both bitmaps and metafiles have their place in computer graphics. Bitmaps are very often used for very complex images originating from the real world, such as digitized photographs. Metafiles are more suitable for human- or machine-generated images, such as architectural drawings. Both bitmaps and metafiles can exist in memory or be stored on a disk as files, and both can be transferred among Windows applications using the clipboard.
You can construct a bitmap ”manually“ using the SDKPAINT program included with the Windows Software Development Kit. You can then include the bitmap as a resource in a resource script file and load it into a program using the LoadBitmap function. This was demonstrated in Chapter 8. In Chapter 9 we saw how bitmaps can substitute for text in a menu. In Chapter 12 we constructed small 8-by-8-pixel bitmaps to use for brushes.
Metafiles are more closely associated with Windows drawing programs (such as Micrografx's Designer) and other CAD (computer-aided design) programs. The user of these programs draws an image with lines, rectangles, ellipses, text, and other graphics primitives. Although these programs generally use a private format for storing the picture in a file, they can usually transfer the picture to the clipboard in the form of a metafile.
Windows 3 supports two different bitmap formats. The first format (sometimes called the ”device-dependent“ format) originated with Windows 1. (I'll be calling this the ”old bitmap.“) The second format is called the ”device-independent bitmap“ (DIB) and is new in Windows 3. The DIB is an extension of the bitmap format supported in the OS/2 1.1 Presentation Manager, and the WINDOWS.H header file contains some structures for working with OS/2 bitmaps.
Bitmaps have two major drawbacks. First, they are highly susceptible to problems involving device dependence. Even the device-independent bitmap is not entirely immune to these problems. The most obvious device dependency is color. Displaying a color bitmap on a monochrome device is often unsatisfactory. Another problem is that a bitmap implies a particular resolution and aspect ratio of an image. Although bitmaps can be stretched or compressed, this process generally involves duplicating or dropping rows or columns of pixels and can lead to distortion in the scaled image. A metafile can be scaled to any size without distortion.
The second major drawback of bitmaps is that they require a large amount of storage space. For instance, a bitmap representation of an entire 640-by-480, 16-color VGA screen requires over 150 KB. Metafiles usually require much less storage space than bitmaps. The storage space for a bitmap is governed by the size of the image and number of colors it contains, whereas the storage space for a metafile is governed by the complexity of the image and the number of individual GDI instructions it contains.
One advantage of bitmaps over metafiles, however, is speed. Copying a bitmap on a video display is usually much faster than rendering a metafile.
In the introduction to GDI in Chapter 11, I talked about two types of device contexts that don't refer to real devices: the memory device context and the metafile device context. We'll see how these work as we examine bitmaps and metafiles and explore the ways we can create, use, and manipulate them. The subject of bitmaps and metafiles will come up again in Chapter 16, ”The Clipboard.“ Text, bitmaps, and metafiles are the three primary forms of data that can be shared by applications through the clipboard.