MFC:CBitmapCreateCompatibleBitmap() 根据传递给它的两个兼容 CDC 给出不同的结果?
MFC: CBitmapCreateCompatibleBitmap() gives different results based on two compatible CDC's passed to it?
为什么传递兼容的 DC 和兼容的 DC 所基于的 CreateCompatibleBitmap()
会给出不同的结果?
这个创建单色位图:
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);
这个创建正确的颜色位图:
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!!
根据评论,查看 CreateCompatibleBitmap
文档:
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 ...
为什么传递兼容的 DC 和兼容的 DC 所基于的 CreateCompatibleBitmap()
会给出不同的结果?
这个创建单色位图:
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);
这个创建正确的颜色位图:
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!!
根据评论,查看 CreateCompatibleBitmap
文档:
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 ...