PRB: Trouble Using DIBSection as a Monochrome Mask (149585)
The information in this article applies to:
- Microsoft Platform Software Development Kit (SDK) 1.0, when used with:
- Microsoft Windows NT Server 3.5
- Microsoft Windows NT Server 3.51
- Microsoft Windows NT Workstation 3.5
- Microsoft Windows NT Workstation 3.51
This article was previously published under Q149585 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.
Modification Type: | Minor | Last Reviewed: | 7/11/2005 |
---|
Keywords: | kbFAQ kbprb KB149585 |
---|
|