BitBlt draws a blank image
I'm using MFC, and I'm trying to draw an image to the screen. I've got the following OnDraw function:
void CgraphicstestView::OnDraw(CDC* pDC)
{
Cgraphicst开发者_如何学GoestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
m_Bitmap.LoadBitmap(IDB_WALL); // m_Bitmap is a CBitmap member of CgraphicstestView
// IDB_WALL is a .png resource
CDC dcMemory;
dcMemory.CreateCompatibleDC(pDC);
dcMemory.SelectObject(&m_Bitmap);
pDC->BitBlt(10, 10, 32, 32, &dcMemory, 0, 0, SRCCOPY);
}
This will draw to the screen, but the destination area is blank. BitBlt is working, since changing SRCCOPY to BLACKNESS draws a black rectangle. Anyone see what I'm missing?
I would have to guess that the problem is that your image is somehow invalid. Because I tested it and it works fine. LoadBitmap returns an HBITMAP, so you could test it like this:
HBITMAP hresult = m_Bitmap.LoadBitmap(IDB_WALL);
assert(hresult);
精彩评论