MFC: CBitmapCreateCompatibleBitmap() gives different results based on two compatible CDC's passed to it?

95 views Asked by At

Why would passing a compatible DC and the DC the compatible one is based on to CreateCompatibleBitmap() give different results?

This one creates a monochrome bitmap:

CDC dcMem; 
dcMem.CreateCompatibleDC(mydc);
destBitmap->CreateCompatibleBitmap(&dcMem, rect.Width(), rect.Height());
CBitmap* pBmpOld = dcMem.SelectObject (destBitmap);
// ... Draw on to the DC ....
dcMem.SelectObject (pBmpOld);

This one creates the correct color bitmap:

CDC dcMem; 
dcMem.CreateCompatibleDC(mydc);
destBitmap->CreateCompatibleBitmap (mydc, rect.Width(), rect.Height());
CBitmap* pBmpOld = dcMem.SelectObject (destBitmap);
// ... Draw on to the DC ....
dcMem.SelectObject (pBmpOld);

TIA!!

1

There are 1 answers

0
Andrew Truckle On BEST ANSWER

As per the comments, have a look at the CreateCompatibleBitmap documentation:

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 ...