怎么用GDI+来实现双缓冲贴图呢

似水流年__ 2010-08-19 04:15:46
自己刚尝试GDI+
感觉不错 大大减少了代码量

可是不知道怎么像GDI中可以COPY,一下子把东西都贴过去,而不是一个一个Draw

望高手支招!Thank you 先
...全文
418 22 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
wanglinhai888 2010-08-24
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 xhk456 的回复:]
我用BitBlt 可是什么都没有画出来 是咋回事呢
我的代码如下


C/C++ code

HDC hMemdc = CreateCompatibleDC(hdc);
Graphics graphics(hMemdc);

//获取窗口标题的高度和窗口宽度
RECT rcWnd;
GetWindowRect(hWnd,&rcWnd)……
[/Quote]
加个CBitmap吧。
似水流年__ 2010-08-23
  • 打赏
  • 举报
回复
楼上的是gdi
BlueMap 2010-08-22
  • 打赏
  • 举报
回复
gdi+双缓冲和gdi相似,先将图片画到内存然后贴图。。。一楼的代码就可行。
关键代码:
CRect clientRect;
GetClientRect(&clientRect);
CDC memDC;
memDC.CreateCompatibleDC(NULL);
CBitmap bitmap;
bitmap.CreateCompatibleBitmap(pDC,clientRect.Width(),clientRect.Height());
memDC.SelectObject(&bitmap);
在menDC中画图
pDC->StretchBlt(0,0,clientRect.Width(),clientRect.Height(),&memDC,0,0,clientRect.Width(),clientRect.Height(),SRCCOPY);//将内存中图片拷贝的客户区
似水流年__ 2010-08-21
  • 打赏
  • 举报
回复
看到好多哦 。。。。。。。。

GDIplus 双缓冲 有点麻烦 。。。
gwq85387566 2010-08-20
  • 打赏
  • 举报
回复
可以用Spy++查看
似水流年__ 2010-08-20
  • 打赏
  • 举报
回复
窗口拖动过程中 都有哪些绘制消息呢
gwq85387566 2010-08-19
  • 打赏
  • 举报
回复
http://blog.csdn.net/scollins/archive/2010/04/20/5507791.aspx
lqfcu2 2010-08-19
  • 打赏
  • 举报
回复
创建内存缓冲位图,先在内存位图上画,画完然后一次BitBlt,

捕获WM_ERASEBKGND消息,直接返回1;
似水流年__ 2010-08-19
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 test_machine 的回复:]
CDC dcMem;
//CWindowDC screenDC(NULL);
CBitmap bitOff;
CRect rcBoundsDP(rcBounds) ;
// Convert bounds to device units.
pdc->LPtoDP(&rcBoundsDP) ;
// The bitmap bounds have 0,0 in the upper-l……
[/Quote]

图是贴上了 比以前闪的还厉害 呵呵
zjz800800 2010-08-19
  • 打赏
  • 举报
回复
不写代码了,只说说原理,何谓双缓冲?
就是写两次,第一次绘制到内存,第二次一次性绘制到屏幕,代码bai goo 去吧。
似水流年__ 2010-08-19
  • 打赏
  • 举报
回复

Image *titleImg = NULL;
Image *amiImg = NULL;
Image *figBorder = NULL;
Image *fig = NULL;
Image *minImg = NULL;
Image *maxImg = NULL;
Image *closeImg = NULL;

titleImg = new Image(L"title.png");
amiImg = new Image(L"Logining.gif");
figBorder = new Image(L"mainfigure_over.png");
fig = new Image(L"figure.png");
minImg = new Image(L"min_nor.png");
maxImg = new Image(L"max_nor.png");
closeImg = new Image(L"close_nor.png");


是指针 因为怕 不停地加载图片 所以在窗口初始化的时候这样做了
test_machine 2010-08-19
  • 打赏
  • 举报
回复
CDC dcMem;
//CWindowDC screenDC(NULL);
CBitmap bitOff;
CRect rcBoundsDP(rcBounds) ;
// Convert bounds to device units.
pdc->LPtoDP(&rcBoundsDP) ;
// The bitmap bounds have 0,0 in the upper-left corner.
CRect rcBitmapBounds(0,0,rcBoundsDP.Width(),rcBoundsDP.Height());
// Create a DC that is compatible with the screen.
//if(m_dcMem
//dcMem.CreateCompatibleDC(&screenDC) ;
dcMem.CreateCompatibleDC(pdc) ;

// Create a really compatible bitmap.
bitOff.CreateCompatibleBitmap(pdc, rcBitmapBounds.Width(), rcBitmapBounds.Height());

// Select the bitmap into the memory DC.
CBitmap* pOldBitmap = dcMem.SelectObject(&bitOff) ;

dcMem.FillSolidRect(0,0, rcBitmapBounds.Width(), rcBitmapBounds.Height(),RGB(255,255,255));
// Save the memory DC state, since DrawMe might change it.
int iSavedDC = dcMem.SaveDC();
//DrawBk(&dcMem);
// Draw our control on the memory DC.
//对m_Graph对象进行绘制
pView->m_Graph.Draw(&dcMem);
//DrawGraph(&dcMem, rcBitmapBounds) ;
//DrawAnnotate(&dcMem);
//运行开始?
//DrawStartPosition(&dcMem);
// Restore the DC, since DrawMe might have changed mapping modes.
dcMem.RestoreDC(iSavedDC) ;
// We don't know what mapping mode pdc is using.
// BitBlt uses logical coordinates.
// Easiest thing is to change to MM_TEXT.
pdc->SetMapMode(MM_TEXT) ;
pdc->SetWindowOrg(0,0) ;
pdc->SetViewportOrg(0,0) ;

//贴图
// Blt the memory device context to the screen.
pdc->BitBlt( rcBoundsDP.left,
rcBoundsDP.top,
rcBoundsDP.Width(),
rcBoundsDP.Height(),
&dcMem,
0,
0,
SRCCOPY) ;

//Clean up.
dcMem.SelectObject(pOldBitmap);
向立天 2010-08-19
  • 打赏
  • 举报
回复
MildSong 2010-08-19
  • 打赏
  • 举报
回复
确认一下,你代码中的 titleImg 是指针吗?
看名称不像,如果不是指针的话,应该用 &titleImg
MildSong 2010-08-19
  • 打赏
  • 举报
回复
从代码执行过程来看我没看出什么问题,那就剩下一种可能,你的图片加载有问题
似水流年__ 2010-08-19
  • 打赏
  • 举报
回复
自己顶下 希望今天把问题给解决了 呵呵
似水流年__ 2010-08-19
  • 打赏
  • 举报
回复
我用BitBlt 可是什么都没有画出来 是咋回事呢
我的代码如下


HDC hMemdc = CreateCompatibleDC(hdc);
Graphics graphics(hMemdc);

//获取窗口标题的高度和窗口宽度
RECT rcWnd;
GetWindowRect(hWnd,&rcWnd);
RECT rcClient;
GetClientRect(hWnd,&rcClient);
int nBottomBorder = GetSystemMetrics(SM_CXEDGE) ;
int nLeftBorder = GetSystemMetrics(SM_CYEDGE) ;
int nWndHeight = rcWnd.bottom-rcWnd.top;
int nWndWidth = rcWnd.right - rcWnd.left;
int nCaptionHeight = nWndHeight - (rcClient.bottom - rcClient.top) - nBottomBorder;

int nCaptionWidth = rcWnd.right - rcWnd.left;


graphics.DrawImage(titleImg,0,0,nLeftBorder,nWndHeight);
graphics.DrawImage(titleImg,nWndWidth-nLeftBorder,0,nLeftBorder,nWndHeight);
graphics.DrawImage(titleImg,0,nWndHeight-nBottomBorder,nWndWidth,nBottomBorder);
graphics.DrawImage(titleImg,0,0,nCaptionWidth,nCaptionHeight);
//graphics.DrawImage(amiImg,100,100);
graphics.DrawImage(figBorder,20,40);
graphics.DrawImage(fig,40,60);
graphics.DrawImage(closeImg,nCaptionWidth-15-28,1);
graphics.DrawImage(maxImg,nCaptionWidth-15-28*2,1);
graphics.DrawImage(minImg,nCaptionWidth-15-28*3-1,1);

BitBlt(hdc,0,0,nWndWidth,nWndHeight,hMemdc,0,0,SRCCOPY);
似水流年__ 2010-08-19
  • 打赏
  • 举报
回复
呵呵 我仔细看了那个例子 那个是双缓冲吗

我怎么看不出来呢?
bdxxxx 2010-08-19
  • 打赏
  • 举报
回复
LS都说的很清楚了 用bitblt
gameslq 2010-08-19
  • 打赏
  • 举报
回复
这是一个列子,希望对你有帮助
http://www.vckbase.com/document/viewdoc/?id=1811
加载更多回复(2)

15,980

社区成员

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

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