11.3.2 Stretching a Bitmap

Your bitmaps are not limited to their original size. You can stretch or compress them by using the StretchBlt function in place of BitBlt. For example, you can quadruple the size of a 64-by-32-pixel bitmap by using the following statement:

StretchBlt(hDC, 100, 30, 128, 64, hdcMemory,
    0, 0, 64, 32, SRCCOPY);

The StretchBlt function has two additional parameters that BitBlt does not. In particular, StretchBlt specifies the width and height of the source bitmap. The first width and height, given as 128 and 64 pixels in the preceding example, apply only to the final size of the bitmap in the destination device context.

To compress a bitmap, StretchBlt removes pixels from the copied bitmap. This means that some of the information in the bitmap is lost when it is displayed. To minimize the loss, you can set the current stretching mode, which StretchBlt uses to combine some of the information with the pixels that will be displayed. The stretching mode can be one of the following:

Mode Purpose

WHITEONBLACK Preserves white pixels at the expense of black pixels; for example, a white outline on a black background.
BLACKONWHITE Preserves black pixels at the expense of white pixels; for example, a black outline on a white background.
COLORONCOLOR Displays color bitmaps. Attempting to combine colors in a bitmap can lead to undesirable effects.

The SetStretchBltMode function sets the stretching mode. In the following example, SetStretchBltMode sets the stretching mode to WHITEONBLACK:

SetStretchBltMode(hDC, WHITEONBLACK);