Microsoft KB Archive/149585

{|
 * width="100%"|

PRB: Trouble Using DIBSection as a Monochrome Mask

 * }

Q149585

-

The information in this article applies to:


 * Microsoft Win32 Software Development Kit (SDK), used with:
 * Microsoft Windows NT Server versions 3.5, 3.51
 * Microsoft Windows NT Workstation versions 3.5, 3.51
 * Microsoft Windows 95
 * Microsoft Windows 2000 Advanced Server
 * Microsoft Windows 2000 Server
 * Microsoft Windows 2000 Professional

-

SYMPTOMS
When using BitBltwith 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 : kbOSWinNT350 kbOSWinNT351 kbSDKWin32 kbOSWin95 kbDSupport kbGDIFAQ

Issue type : kbprb

Technology : kbWin32SDKSearch kbAudDeveloper kbSDKSearch kbWin32sSearch