急!!求助!100分在线等待!~~~双缓存画图,是否只能画黑白色图?我想画高位的彩图,但是显示的却老是黑白色图,而且添家颜色也不行,望高手指教,最好有源代码,在线等待!~

xpaisq 2009-02-23 08:16:14
急!!求助!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!~

...全文
163 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
DRACULAX05 2009-02-23
  • 打赏
  • 举报
回复
// 为屏幕DC创建兼容的内存DC
CDC* pDesktopDC = GetDC(GetDesktopWindow());
if(!m_dcMemory.CreateCompatibleDC(pDesktopDC )) 我感觉是这里的问题,可能创建的是光栅设备环境,画图只能是单色的,但是画高色的方法却没有,也许没找到,望大虾指教
{
::PostQuitMessage(0);
}

// 创建位图
m_Bmp.CreateCompatibleBitmap(pDesktopDC , rt.Width(), rt.Height());
lwx300 2009-02-23
  • 打赏
  • 举报
回复
//试试改为这样的形式,然后在 OnDraw 中调用函数。

void CDBBTestView::DrawManyCircleUseDBB(CDC *pDC)
{
...
CMemDc dcMemory;
CBitmap Bmp;
dcMemory.CreateCompatibleDC(pDC) //创建与指定 DC 兼容的内存 DC。
Bmp.CreateCompatibleBitmap(pDC, rt.Width(), rt.Height()); //不要使用 &dcMemory。
...
}

DarknessTM 2009-02-23
  • 打赏
  • 举报
回复
m_dcMemory.CreateCompatibleDC(NULL)

这里要传入 支持彩色的DC,否则使用的是只有黑白两色的基础dc

你应该在程序里保存 Bitmap, 而不是 内存DC, 内存DC在每次 paint的时候都创建,然后select bitmap 再BitBlt
xpaisq 2009-02-23
  • 打赏
  • 举报
回复
好了揭贴给分,谢谢各位的鼎立帮忙!
Hiiishe 2009-02-23
  • 打赏
  • 举报
回复

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);
}

}
cnzdgs 2009-02-23
  • 打赏
  • 举报
回复
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);
}

19,464

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧