Discussion:
Did you know a memDC creates only monochrome bitmaps?
(too old to reply)
myprasanna
2009-09-02 03:11:01 UTC
Permalink
HDC hScreenDC = CreateDC ( TEXT("DISPLAY"), NULL, NULL, NULL );
VERIFY(hScreenDC); // Create a DC for screen

HDC hMemDC = CreateCompatibleDC(hScreenDC);
VERIFY(hMemDC); // Create a memory buffer DC

HBITMAP hMemBitmap = CreateCompatibleBitmap(hMemDC, rectDesktop.right,
rectDesktop.bottom); // Create a compatible bitmap.
VERIFY(hMemBitmap);

The above code causes hMemBitmap to be a monochrome bitmap !

replacing the last line by:

HBITMAP hMemBitmap = CreateCompatibleBitmap(hScreenDC, rectDesktop.right,
rectDesktop.bottom); // Create a compatible bitmap to screenDC
VERIFY(hMemBitmap);


Now this makes it a 32-bit BMP. Did you guys know this?
None of the msdn docs seem to mention anything of this sort. This is why I
hate the GDI. Large portions of it, are left to guessing. :(
Ivan Brugiolo [MSFT]
2009-09-02 06:47:09 UTC
Permalink
A Device Context, by default, has selected in a ***@1bpp surface.
Try selecting in a different surface.
The second usage seems more common practice than the first one
--
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of any included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
Post by myprasanna
HDC hScreenDC = CreateDC ( TEXT("DISPLAY"), NULL, NULL, NULL );
VERIFY(hScreenDC); // Create a DC for screen
HDC hMemDC = CreateCompatibleDC(hScreenDC);
VERIFY(hMemDC); // Create a memory buffer DC
HBITMAP hMemBitmap = CreateCompatibleBitmap(hMemDC, rectDesktop.right,
rectDesktop.bottom); // Create a compatible bitmap.
VERIFY(hMemBitmap);
The above code causes hMemBitmap to be a monochrome bitmap !
HBITMAP hMemBitmap = CreateCompatibleBitmap(hScreenDC, rectDesktop.right,
rectDesktop.bottom); // Create a compatible bitmap to screenDC
VERIFY(hMemBitmap);
Now this makes it a 32-bit BMP. Did you guys know this?
None of the msdn docs seem to mention anything of this sort. This is why I
hate the GDI. Large portions of it, are left to guessing. :(
Richard Russell
2009-09-02 08:21:52 UTC
Permalink
Post by myprasanna
The above code causes hMemBitmap to be a monochrome bitmap !
None of the msdn docs seem to mention anything of this sort.
Yes they do. The docs for CreateCompatibleDC state "When the memory
DC is created, its display surface is exactly one monochrome pixel
wide and one monochrome pixel high":

http://msdn.microsoft.com/en-us/library/dd183489.aspx

The docs for CreateCompatibleBitmap state "The color format of the
bitmap ... matches the color format of the device identified by the
hdc parameter":

http://msdn.microsoft.com/en-us/library/dd183488.aspx

Together, the implication is that the resulting bitmap will be
monochrome, in the circumstances you described.

Richard.
http://www.rtrussell.co.uk/
To reply by email change 'news' to my forename.
Remy Lebeau
2009-09-02 18:12:33 UTC
Permalink
Post by Richard Russell
The docs for CreateCompatibleBitmap state
<snip>

It also states:

"When a memory device context is created, it initially has a 1-by-1
monochrome bitmap selected into it. If this memory device context is used in
CreateCompatibleBitmap(), the bitmap that is created is a monochrome bitmap.
To create a color bitmap, use the HDC that was used to create the memory
device context"
--
Remy Lebeau (TeamB)
Remy Lebeau
2009-09-02 18:11:19 UTC
Permalink
Post by myprasanna
HDC hScreenDC = CreateDC ( TEXT("DISPLAY"), NULL, NULL, NULL );
Use GetDC(0) instead.
Post by myprasanna
HDC hMemDC = CreateCompatibleDC(hScreenDC);
Alternatively, you can use CreateCompatibleDC(0) instead.
Post by myprasanna
The above code causes hMemBitmap to be a monochrome bitmap !
It is supposed to. That is covered in the documentation:

CreateCompatibleBitmap Function
http://msdn.microsoft.com/en-us/library/dd183488(VS.85).aspx

Note: When a memory device context is created, it initially has a 1-by-1
monochrome bitmap selected into it. If this memory device context is used in
CreateCompatibleBitmap(), the bitmap that is created is a monochrome bitmap.
To create a color bitmap, use the HDC that was used to create the memory
device context, as shown in the following code:

HDC memDC = CreateCompatibleDC ( hDC );
HBITMAP memBM = CreateCompatibleBitmap ( hDC, nWidth, nHeight );
SelectObject ( memDC, memBM );
<snip>
Post by myprasanna
Now this makes it a 32-bit BMP. Did you guys know this?
Yes, because it is in the documentation. The solution you discovered is
exactly what the documentation actually says to do.
Post by myprasanna
None of the msdn docs seem to mention anything of this sort.
Yes, actually it does. See above.
--
Remy Lebeau (TeamB)
Loading...