将 CView 内容复制到位图
我想创建 CView 当前内容的位图副本,该副本当前可能在屏幕上可见,也可能不可见。以下是我添加到 OnDraw 函数中的代码:
void
MyView::OnDraw
(
CDC* pDC
)
{
... normal processing ...
// Copy the view contents to a bitmap.
CDC dc;
dc.CreateCompatibleDC( pDC );
if ( m_pBitmap != NULL )
{
delete m_pBitmap;
}
m_pBitmap = new CBitmap();
m_pBitmap->CreateCompatibleBitmap( &dc, szView.cx, szView.cy );
CBitmap* pOld = ( CBitmap* )dc.SelectObject( m_pBitmap );
dc.BitBlt( 0, 0, szView.cx, szView.cy, pDC, 0, 0, SRCCOPY );
dc.SelectObject( pOld );
}
但现在当我检查位图时,我可以看到每个像素只有 1 位。我确定我错过了一些东西,有人可以帮忙吗?
谢谢, 凯文
I'd like to create a bitmap copy of the current contents of my CView, which may or may not be currently visible on the screen. Here is the code I've added to my OnDraw function:
void
MyView::OnDraw
(
CDC* pDC
)
{
... normal processing ...
// Copy the view contents to a bitmap.
CDC dc;
dc.CreateCompatibleDC( pDC );
if ( m_pBitmap != NULL )
{
delete m_pBitmap;
}
m_pBitmap = new CBitmap();
m_pBitmap->CreateCompatibleBitmap( &dc, szView.cx, szView.cy );
CBitmap* pOld = ( CBitmap* )dc.SelectObject( m_pBitmap );
dc.BitBlt( 0, 0, szView.cx, szView.cy, pDC, 0, 0, SRCCOPY );
dc.SelectObject( pOld );
}
But now when I examine the bitmap I can see that there is only 1 bit per pixel. I'm sure I'm missing something, can anyone help?
Thanks,
Kevin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是在调用 CreateCompatibleBitmap 时需要将 &dc 更改为 pDC。
凯文
The problem was that &dc needed to be changed to pDC in the call to CreateCompatibleBitmap.
Kevin