急!!求助!100分在线等待!~~~双缓存画图,是否只能画黑白色图?我想画高位的彩图,但是显示的却老是黑白色图,而且添家颜色也不行,望高手指教,最好有源代码,在线等待!~
下面是我的代码片段:
// 初始化和双缓冲相关的要素
void CDBBTestView::InitialDBB()
{
CRect rt;
this->GetClientRect(&rt); // 为屏幕DC创建兼容的内存DC
if(!m_dcMemory.CreateCompatibleDC(NULL)) 我感觉是这里的问题,可能创建的是光栅设备环境,画图只能是单色的,但是画高色的方法却没有,也许没找到,望大虾指教
{
::PostQuitMessage(0);
} // 创建位图
m_Bmp.CreateCompatibleBitmap(&m_dcMemory, rt.Width(), rt.Height()); // 相当于选择画布
::SelectObject(m_dcMemory.GetSafeHdc(), m_Bmp);

}下面函数是画图void CDBBTestView::DrawManyCircleUseDBB()
{
// 在View内用双缓冲画很多的圆 CDC *pdcView = this->GetDC(); CRect rt;
this->GetClientRect(&rt); m_dcMemory.FillSolidRect(&rt, 0x00FFFFFF); // 白色填充, 注意,这次是画在内存设备环境上 // 画圆
for(int i = 0; i < rt.Width() - 1; i+= 16)
{
for(int j = 0; j < rt.Height() - 1; j+= 16)
{
m_dcMemory.Ellipse(i, j, i + m_nRadius, j + m_nRadius);
}
} // 一次性的将内存设备环境上绘制完毕的图形"贴"到屏幕上
pdcView->BitBlt(0, 0, rt.Width(), rt.Height(), &m_dcMemory, 0, 0, SRCCOPY); this->ReleaseDC(pdcView); // 释放view的设备环境
}
急!!在线着急等待,help!~

解决方案 »

  1.   

    m_dcMemory.CreateCompatibleDC(NULL)这里要传入 支持彩色的DC,否则使用的是只有黑白两色的基础dc你应该在程序里保存 Bitmap, 而不是 内存DC, 内存DC在每次 paint的时候都创建,然后select bitmap 再BitBlt
      

  2.   

    //试试改为这样的形式,然后在 OnDraw 中调用函数。void CDBBTestView::DrawManyCircleUseDBB(CDC *pDC) 
    {
       ...
       CMemDc dcMemory;
       CBitmap Bmp;
       dcMemory.CreateCompatibleDC(pDC) //创建与指定 DC 兼容的内存 DC。
       Bmp.CreateCompatibleBitmap(pDC, rt.Width(), rt.Height()); //不要使用 &dcMemory。
       ...
    }
      

  3.   

    // 为屏幕DC创建兼容的内存DC
    CDC* pDesktopDC = GetDC(GetDesktopWindow()); 
    if(!m_dcMemory.CreateCompatibleDC(pDesktopDC )) 我感觉是这里的问题,可能创建的是光栅设备环境,画图只能是单色的,但是画高色的方法却没有,也许没找到,望大虾指教 

    ::PostQuitMessage(0); 
    } // 创建位图 
    m_Bmp.CreateCompatibleBitmap(pDesktopDC , rt.Width(), rt.Height());
      

  4.   

    void CDBBTestView::InitialDBB()
    {
    CClientDC dc(this);
    CRect rt;
    this->GetClientRect(&rt);
    if(!m_dcMemory.CreateCompatibleDC(&dc))
    {
    ::PostQuitMessage(0);
    }
    m_Bmp.CreateCompatibleBitmap(&dc, rt.Width(), rt.Height());
    ::SelectObject(m_dcMemory.GetSafeHdc(), m_Bmp);
    }
      

  5.   


    OnDraw(CDC* pDC)
    {
    CDC dc;
    CDC* pDrawDC = pDC;
    CBitmap bitmap;
    CBitmap* pOldBitmap = 0; // only paint the rect that needs repainting
    CRect client;
    pDC->GetClipBox(client);
    CRect rect = client;
    DocToClient(rect); if (!pDC->IsPrinting())
    {
    // draw to offscreen bitmap for fast looking repaints
    if (dc.CreateCompatibleDC(pDC))
    {
    if (bitmap.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height()))
    {
    OnPrepareDC(&dc, NULL);
    pDrawDC = &dc; // offset origin more because bitmap is just piece of the whole drawing
    dc.OffsetViewportOrg(-rect.left, -rect.top);
    pOldBitmap = dc.SelectObject(&bitmap);
    dc.SetBrushOrg(rect.left % 8, rect.top % 8); // might as well clip to the same rectangle
    dc.IntersectClipRect(client);
    }
    }
    }       // 绘制到内存DC
            XXXX.Draw( pDrawDC);       // 把内存DC内容贴到pDC上
    if (pDrawDC != pDC)
    {
    pDC->SetViewportOrg(0, 0);
    pDC->SetWindowOrg(0,0);
    pDC->SetMapMode(MM_TEXT);
    dc.SetViewportOrg(0, 0);
    dc.SetWindowOrg(0,0);
    dc.SetMapMode(MM_TEXT);
    pDC->BitBlt(rect.left, rect.top, rect.Width(), rect.Height(),
    &dc, 0, 0, SRCCOPY);
    dc.SelectObject(pOldBitmap);
    }}