我程序的作用使在试图窗口显示一副位图:部分代码如下:
class CFontDemoView : public CView
{
protected: // create from serialization only
    CBitmap m_Bitmap;
// Operations
public:
Display(CDC *pdc,CBitmap *pbitmap,int x,int y);
}
/////////////////////////////////////////////////
// CFontDemoView message handlers
CFontDemoView :: Display(CDC *pdc,CBitmap *pbitmap,int x,int y)
{
BITMAP BM;
CDC MemDC;
MemDC.CreateCompatibleDC (NULL);
MemDC.SelectObject (pbitmap);
pbitmap->GetObject (sizeof(BM),&BM);
pdc->BitBlt (x,y,BM.bmWidth ,BM.bmHeight ,&MemDC,0,0,SRCCOPY);}
/////----------------------------------------------------
void CFontDemoView::OnDraw(CDC* pDC)
{
CFontDemoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
    CFontDemoView ::Display (pDC,&m_Bitmap,300,100);
}
问题:
   运行后在我得视图窗口显示的却不是一副真彩色的图片,而是想照片的底片一样的,(不是黑白色)。请问什么原因?

解决方案 »

  1.   

    补充:我的位图已经初始化过:CFontDemoView::CFontDemoView()
    {

    // TODO: add construction code here m_Bitmap.LoadBitmap(IDB_BITMAP2);
    }
      

  2.   

    //这样试试:
    CFontDemoView :: Display(CDC *pdc,CBitmap *pbitmap,int x,int y)
    {
    BITMAP BM;
    CDC MemDC;
    MemDC.CreateCompatibleDC ( pdc );//NULL);
    CBitmap* pOldBM = MemDC.SelectObject (pbitmap);
    pbitmap->GetObject (sizeof(BM),&BM);
    pdc->BitBlt (x,y,BM.bmWidth ,BM.bmHeight ,&MemDC,0,0,SRCCOPY);
             MemDC.SelectObject ( pOldBM );
    }
      

  3.   

    MemDC.CreateCompatibleDC (NULL); //Not NULL, But pdc
      

  4.   

    我的代码,工作正常 if(!memDC.m_hDC)
    {
    memDC.CreateCompatibleDC(pDC);//注意这里是pDC
    }
    CWrapBitmap* pWrapBitmap=pDoc->GetWrapBitmap();
    if(!pWrapBitmap->GetpBitmap())
    return;
    memDC.SelectObject(pWrapBitmap->GetpBitmap());
    pDC->BitBlt(0,0,pWrapBitmap->GetWidth(),pWrapBitmap->GetHeight(),&memDC,0,0,SRCCOPY);
      

  5.   

    CDC MemDC;CClientDC dc(NULL);
    //MemDC.CreateCompatibleDC (NULL);
    MemDC.CreateCompatibleDC (&dc);
      

  6.   

    你的CDC MemDC;定义错误,请你改为CClientDC MemDC(this);这样就可以画在客户区了。