PRB: Trouble Using DIBSection as a Monochrome Mask

Last reviewed: January 29, 1998
Article ID: Q149585

The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK) on the following platforms:

        - Microsoft Windows NT versions 3.5, 3.51
        - Microsoft Windows 95
    

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 : GdiBmp
Version : WINNT:3.5,3.51;Win95
Platform : Win95 winnt
Issue type : kbprb


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 29, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.