Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 650
  • Last Modified:

Copy CView contents to a bitmap

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:

    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
1 Solution
the bitmap you get is compatible to the device context you passed in as first argument to CreateCompatibleBitmap. here you used &dc which is compatible with pDC. the pDC should be compatible with your screen device. so it should be the pointer passed to OnDraw as argument and not a new (monochrome) device context.

kjc1111Author Commented:
Thanks Sara, that worked great!


Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now