在用双缓冲方式画图时,显示出的图形全黑。
我用了   HPEN pen=CreatePen(PS_SOLID, 4, color);
HPEN oldpen=NULL;
oldpen=(HPEN)::SelectObject(m_dcMemory.GetSafeHdc(), pen); 
自定义画笔还是不能显示出颜色。
不用双缓冲没有这个问题。

解决方案 »

  1.   

    你创建内存DC时,是不是没有从屏幕DC创建兼容DC? 内存DC默认好像是黑白的哦~~
      

  2.   

    兼容DC是为了解决GDI对象位图的操作问题的。因为窗体等显示的都是位图,所以为了修改显示,应该先在一个兼容dc中把要显示的位图画好,然后再显示到屏幕上来。你没有把位图选进DC吧
    看MSDN的说明:
    Memory Device Contexts
    The memory device context stores bitmapped images for a particular device. An application can create a memory device context by calling the CreateCompatibleDC function and supplying a handle that identifies a device context for a particular device. When the system processes this call, it creates a bitmap having a color format compatible with the original device. Because the bitmap is compatible with the given device, a memory device context is also sometimes referred to as a compatible device context. The original bitmap in a memory device context is simply a placeholder. Its dimensions are one pixel by one pixel. Before an application can begin drawing, it must select a bitmap with the appropriate width and height into the device context by calling the SelectObject function. Once the new bitmap is selected into the memory device context, an application can begin using the device context to store images. For more information about bitmaps and bitmap operations, see Bitmaps. 
      

  3.   

    下面是我创建内存DC的代码,应该没什么错阿。GetClientRect(&rt);
    if(!m_dcMemory.CreateCompatibleDC(pDC))  //pDC为屏幕DC
    {
        ::PostQuitMessage(0);
    }
    // 创建位图
    m_Bmp.CreateCompatibleBitmap(&m_dcMemory, rt.Width(), rt.Height());
    ::SelectObject(m_dcMemory.GetSafeHdc(), m_Bmp);
      

  4.   

    m_Bmp.CreateCompatibleBitmap(&m_dcMemory, rt.Width(), rt.Height());改为:m_Bmp.CreateCompatibleBitmap(pDC, rt.Width(), rt.Height());
      

  5.   

    hansa,你是什么操作系统,内存多大?偶用win2000试了没有这个问题,3000*3000也是正常的。
    只是这种方法创建的位图,在改变桌面分辨率后可能会出问题。 10000*10000的256色位图已经超过256兆了,偶的机器根本创建不了,直接返回空。
      

  6.   

    当位图尺寸很大,比如10000×10000时,再想绘图就需要更改坐标系了,用pDC->SetMapMode(MM_ANISOTROPIC)就可以实现了,同时还要调用SetViewportOrg()、SetViewportExt()、SetWindowExt()这几个函数调整坐标系设置。完成以上操作后就可以在内存中完成你的绘图操作。在内存中绘完图后再将位图拷贝到屏幕上,用BitBlt()函数实现