PRB: Memory DC Produces Monochrome ImagesLast reviewed: November 14, 1995Article ID: Q139165 |
The information in this article applies to:
SYMPTOMSWhen you create and use a memory Device Context (DC) to draw and store GDI images, the bitmap displayed when transferred from the memory device context to the physical display is monochrome. All colors are converted to either black or white.
CAUSEWhen creating a compatible bitmap for the memory DC, the handle to the memory DC is used as the first parameter to the call to CreateCompatibleBitmap(). This creates a monochrome bitmap because a memory DC created with CreateCompatibleDC() is given a 1x1 monochrome bitmap as its default bitmap. For example, the following code creates a monochrome bitmap and selects it into a memory DC:
HDC hdc, hdcMem; HBITMAP hBitmap; hdc = GetDC(hWnd); hdcMem = CreateCompatibleDC(hdc); hBitmap = CreateCompatibleBitmap(hdcMem, 400, 400); SelectObject(hdcMem, hBitmap); SetTextColor(hdcMem, RGB(0, 0, 255)); RESOLUTIONSend a physical screen DC to the CreateCompatibleBitmap() function rather than the memory DC that you plan on selecting the bitmap into. The following example code properly sets up a color memory DC with a color bitmap with the same bit depth as the physical display:
HDC hdc, hdcMem; HBITMAP hBitmap; hdc = GetDC(hWnd); hdcMem = CreateCompatibleDC(hdc); hBitmap = CreateCompatibleBitmap(hdc, 400, 400); SelectObject(hdcMem, hBitmap); SetTextColor(hdcMem, RGB(0, 0, 255)); STATUSThis behavior is by design.
|
Additional reference words: 3.10 4.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |