如何将位图绘制到Picture控件的一部分?

时间:2017-05-01 16:31:20

标签: c++ windows winapi mfc

我正在尝试将位图绘制到CDC的一部分中。我加载bmp,BitBlt CDC的位图信息,没有任何显示,这是我的代码:

CWnd* pWindow = GetParent()->GetDlgItem(IDC_DIAGRAM);
CClientDC windowDC(pWindow);
CDC* CDC = windowDC;
// I draw the graph and other objects I need here, everything works perfectly so far

HANDLE hBitMap = ::LoadImage(0, L"Diagram.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
CBitmap bmp;
bmp.Attach((HBITMAP)hBitMap);
// For testing purposes I tried drawing this bmp into a separate picture control with the bmp property turned on and it drew fine, So i know the data is loaded properly.
CDC->SelectObject(bmp);
// start Position = (0,0) , width = 500, height = 500, imageStartPos = (0,0)
CDC->BitBlt(0, 0, 500, 500, &CDC, 0, 0, SRCCOPY);

在以下代码没有显示之后,我期待的是:

 _____________
|     |      |
| BMP |      |
|_____|      |
|            |
|    CDC     |
|            |
|            |
______________

有没有办法做到这一点,而不必将图片控件叠加在一起?

编辑:让它工作,工作代码是:

CDC* CDC = windowDC;
CDC* bmDC;
CClientDC dc(this);
// Load bmp the same way as above
bmDC->SelectObject(bmp);
bmDC->CreateCompatibleDC(&dc);
CDC->BitBlt(0, 0, 500, 500, bmDC, 0, 0, SRCCOPY);

0 个答案:

没有答案