Color Conversions

If the destination and source device contexts in the BitBlt call have different color characteristics, Windows must convert the bitmap from one color format to another. The best color conversion occurs when the source bitmap is monochrome. Windows uses the text color and background color attributes in the destination device context for this conversion:

Monochrome DC
(Source)
Color DC
(Destination)

0 (Black) Text color (default is black)
1 (White) Background color (default is white)

The background color attribute, which you encountered in Chapter 12, is the color Windows uses to fill in the gaps in dotted and dashed lines and between the hatches in hatched brushes. You can change the background color with SetBkColor. The text color, which you'll encounter in Chapter 14, determines the color of text. You can change this with SetTextColor. With default settings, the monochrome bitmap simply turns into a black-and-white bitmap on the color device context.

Translating a bitmap in a color source device context to a monochrome destination device context is less satisfactory:

Color DC
(Source)
Monochrome DC
(Destination)

Pixel != Background color 0 (Black)
Pixel == Background color 1 (White)

In this case Windows uses the background color of the source device context to determine what color is translated to white. Every other color is translated to black.

Here's another color-related problem: Windows needs to equate a particular combination of color bits in the bitmap (either in different planes or in the same plane) to the 24-bit color value of the background color. This means that the color device context must refer to a real device or be a memory device context based on a real device. For instance, suppose you have a monochrome device driver. You create a memory device context based on the screen device context and select a color bitmap into that memory device context. You now try to transfer that bitmap to a monochrome device context. It won't work, because Windows doesn't know how the multiple planes or multiple bits per pixel in the memory device context bitmap relate to real colors.