PRB: Trouble Using DIBSection as a Monochrome Mask

ID: Q149585


The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK), used with:
    • Microsoft Windows NT, versions 3.5, 3.51
    • Microsoft Windows 95
  • Microsoft Windows 2000


SYMPTOMS

When using BitBlt()with DIBSections to create a monochrome mask, the target pixel color is chosen without regard for the background color in the target device context. The AND mask that results is not what the programmer intended, and subsequent transparent blts using that mask do not maintain proper transparency.


CAUSE

On both Windows NT versions 3.5 and 3.51 and Windows 95, using BitBlt() with a DIBSection as a target results in color matching without regard for the current background color. This means that GDI decides whether black or white would be a closer match for each color in the bitmap and sets the target pixel accordingly. This behavior also occurs on Windows 95 if the source bitmap is a DIBSection.


RESOLUTION

Either use a Device Dependent Bitmaps (DDB), or set (or read) the pixels in the DIBSection(s) manually. To perform this task manually would require checking each pixel against the background color and setting the target pixel to white for those that match.


STATUS

This behavior is by design.


MORE INFORMATION

A commonly used method for creating an AND mask for transparent BitBlts involves blting the color source image to a monochrome bitmap. When converting color to monochrome, BitBlt() uses the background color (set with SetBkColor()) to determine which pixels should be white and which should be black. However, this is true only for device dependent bitmaps. When the target of a BitBlt() is a DIBSection, color matching is always performed. This means that, for a DIBSection, the background color is ignored, and colors in the source image are matched to white or black based on color matching. On Windows 95, this behavior also occurs if the source bitmap is a DIBSection.

Additional query words: CreateDIBSection StretchBlt BitBlt mono transparency

Keywords : kbNTOS350 kbNTOS351 kbSDKWin32 kbWinOS95 kbDSupport kbGDIFAQ
Version : WINDOWS:95
Platform : WINDOWS
Issue type : kbprb


Last Reviewed: December 15, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.