gdi+开了双缓冲还是闪? dc.FillSolidRect(&rect,GetSysColor(COLOR_BTNFACE));能不能 不要 ? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可是双缓冲不是这样用的啊应该在一个工作线程中完成内存dc中的绘制,在paint函数中的工作只是把内存dc拷贝一下,否则耗时的操作还是在界面线程中执行的,该慢还是慢 dc.FillSolidRect(&rect,GetSysColor(COLOR_BTNFACE));已经 操作 一次 dc 了双缓冲 是 全部 操作 在 memDC 里。一次 操作 dc。 或者: g.FillRectangle(&brush, 0, 0, image.GetWidth(), image.GetHeight()); SolidBrush brush(GetSysColor(COLOR_BTNFACE)); memgr->FillRectangle(&brush,-rect.Width()/2,-rect.Height()/2,rect.Width(),rect.Height());还是不行啊 Graphics graphics(dc.m_hDC);这是用的dc 吧 我有点迷糊了?CDC pdc;pdc.CreateCompatibleDC(&dc);Graphics graphics(pdc.m_hDC);Image image(......);graphics.DrawImage(&image,.......);dc.bitblt(......); id=SetTimer(1,100,NULL); CPaintDC dc(this); CDC pdc; pdc.CreateCompatibleDC(&dc); Graphics graphics(pdc.m_hDC); GetClientRect(&rect); graphics.TranslateTransform((REAL)rect.right/2,(REAL)rect.bottom/2); graphics.RotateTransform(hudu);Image image(L"3.png");graphics.DrawImage(&image,-rect.Width()/2,-rect.Height()/2,rect.Width(),rect.Height()); dc.BitBlt(rect.left,rect.top,rect.Width(),rect.Height(),&pdc,-rect.Width()/2,-rect.Height()/2,SRCCOPY);这样写对不对啊? id=SetTimer(1,100,NULL); 在初始化里吧 ? CDC pdc; pdc.CreateCompatibleDC(&dc);pdc 并没有大小? 要SelectObject 一个bitmap 吧 只能 使用 dc :Graphics graphics(dc.m_hDC);不能使用 memDC ? 下面是 没旋转时的代码: CRect rect; rect.SetRect(0,0,128,119);// CDC memDC; memDC.CreateCompatibleDC(&dc); HBITMAP hbmp=CreateCompatibleBitmap(dc.m_hDC,rect.Width(),rect.Height()); memDC.SelectObject(hbmp); Graphics graphics(memDC.m_hDC);// SolidBrush brush(GetSysColor(COLOR_BTNFACE)); graphics.FillRectangle(&brush,0,0,rect.Width(),rect.Height());//// rotate graphics.RotateTransform(0.0);// Image image(L"3.png"); graphics.DrawImage(&image,0,0,rect.Width(),rect.Height()); HDC hdc = graphics.GetHDC(); ::BitBlt(dc.m_hDC,0,0,rect.Width(),rect.Height(),hdc,0,0,SRCCOPY); graphics.ReleaseHDC(hdc); 带蓝边: CRect rect; rect.SetRect(0,0,90,91);// CDC memDC; memDC.CreateCompatibleDC(&dc); HBITMAP hbmp=CreateCompatibleBitmap(dc.m_hDC,rect.Width(),rect.Height()); memDC.SelectObject(hbmp);// Graphics graphics(memDC.m_hDC);// argb SolidBrush brush(Color(255,0,0,255));/// 蓝边 !!!! graphics.FillRectangle(&brush,0,0,rect.Width(),rect.Height());//// move// graphics.TranslateTransform((REAL)0.0,0.0);// rotate// graphics.RotateTransform(0.0);// Image image(L"3.png"); graphics.DrawImage(&image,1,1,rect.Width()-2,rect.Height()-2); HDC hdc = graphics.GetHDC(); ::BitBlt(dc.m_hDC,0,0,rect.Width(),rect.Height(),hdc,0,0,SRCCOPY); graphics.ReleaseHDC(hdc); 之前的代码在win7下好像不闪,在xp下明显有闪烁??????? OS win7, vc6 上 运行正常。蓝边的 那个(一点宽) 是 为了说明 graphics.FillRectangle(&brush,0,0,rect.Width(),rect.Height());// 已 作用。黑的原因是:HBITMAP hbmp=CreateCompatibleBitmap(dc.m_hDC,rect.Width(),rect.Height());一定不能 是 memDC !!! 这句:::BitBlt(dc.m_hDC,0,0,rect.Width(),rect.Height(),hdc,0,0,SRCCOPY);牵涉到 GDI 与 GDI+ 混合 编程的问题。 下面是纯 gdi+ : CPaintDC dc(this); // device context for painting Bitmap CacheImage(90, 90); Graphics CacheGraphics(&CacheImage ); // 对 CacheImage 进行描画 SolidBrush brush(Color(255,0,0,255));// argb CacheGraphics.FillRectangle(&brush,0,0,90,90);// Image image(L"3.png"); CacheGraphics.DrawImage(&image,1,1,88,88);// 获得窗口的 Graphics 对象 Graphics Graphic(dc.m_hDC); // 将描画好的 CacheImage 画到窗口上 Graphic.DrawImage(&CacheImage, 0, 0); 应该是画背景的原因吧,不画背景应该就好了。在if(!AfxRegisterClass(&wndcls)) 的前面注释下面的语句//wndcls.hbrBackground = (HBRUSH)backGrush.m_hObject; +1 之前也遇到这个问题,后来发现CreateCompatibleBitmap传入的如果是内存DC的话,默认创建的是1*1的单色位图,所以才会出现上面所说的黑块. 如果是视频兼容DC,就会是彩色的. 一不小心很容易掉坑里头. 关于控制的问题 用GDI+怎么画一个有一定旋转角度的矩形?急 请问哪里有VC6英文企业版下载? 关于如何在读取纪录的时候用进度指示器显示进度? 如何屏蔽对话框的ESC Enter 等功能键? 请问如何使用ADO与该表建立连接 Socket编程问题:在局域网中,不知道服务器端的IP地址的情况下如何发送信息给服务器? wince 如何测试内存 CRichEditCtrl在98下出现怪码,怎么回事? 多线程菜鸟问题 MFC 两个对话框 数据传递问题 cpoint对象怎么做与逻辑判断啊
应该在一个工作线程中完成内存dc中的绘制,在paint函数中的工作只是把内存dc拷贝一下,否则耗时的操作还是在界面线程中执行的,该慢还是慢
已经 操作 一次 dc 了
双缓冲 是 全部 操作 在 memDC 里。
一次 操作 dc。
g.FillRectangle(&brush, 0, 0, image.GetWidth(), image.GetHeight());
memgr->FillRectangle(&brush,-rect.Width()/2,-rect.Height()/2,rect.Width(),rect.Height());
还是不行啊
这是用的dc 吧
我有点迷糊了?CDC pdc;
pdc.CreateCompatibleDC(&dc);
Graphics graphics(pdc.m_hDC);
Image image(......);
graphics.DrawImage(&image,.......);
dc.bitblt(......);
CPaintDC dc(this);
CDC pdc;
pdc.CreateCompatibleDC(&dc);
Graphics graphics(pdc.m_hDC);
GetClientRect(&rect);
graphics.TranslateTransform((REAL)rect.right/2,(REAL)rect.bottom/2);
graphics.RotateTransform(hudu);
Image image(L"3.png");
graphics.DrawImage(&image,-rect.Width()/2,-rect.Height()/2,rect.Width(),rect.Height());
dc.BitBlt(rect.left,rect.top,rect.Width(),rect.Height(),&pdc,-rect.Width()/2,-rect.Height()/2,SRCCOPY);这样写对不对啊?
在初始化里吧 ?
CDC pdc;
pdc.CreateCompatibleDC(&dc);
pdc 并没有大小?
要SelectObject 一个bitmap 吧
不能使用 memDC ?
rect.SetRect(0,0,128,119);
//
CDC memDC;
memDC.CreateCompatibleDC(&dc); HBITMAP hbmp=CreateCompatibleBitmap(dc.m_hDC,rect.Width(),rect.Height());
memDC.SelectObject(hbmp); Graphics graphics(memDC.m_hDC);
//
SolidBrush brush(GetSysColor(COLOR_BTNFACE));
graphics.FillRectangle(&brush,0,0,rect.Width(),rect.Height());//
// rotate
graphics.RotateTransform(0.0);
//
Image image(L"3.png");
graphics.DrawImage(&image,0,0,rect.Width(),rect.Height());
HDC hdc = graphics.GetHDC();
::BitBlt(dc.m_hDC,0,0,rect.Width(),rect.Height(),hdc,0,0,SRCCOPY);
graphics.ReleaseHDC(hdc);
rect.SetRect(0,0,90,91);
//
CDC memDC;
memDC.CreateCompatibleDC(&dc);
HBITMAP hbmp=CreateCompatibleBitmap(dc.m_hDC,rect.Width(),rect.Height());
memDC.SelectObject(hbmp);
//
Graphics graphics(memDC.m_hDC);
// argb
SolidBrush brush(Color(255,0,0,255));/// 蓝边 !!!!
graphics.FillRectangle(&brush,0,0,rect.Width(),rect.Height());//
// move
// graphics.TranslateTransform((REAL)0.0,0.0);
// rotate
// graphics.RotateTransform(0.0);
//
Image image(L"3.png");
graphics.DrawImage(&image,1,1,rect.Width()-2,rect.Height()-2);
HDC hdc = graphics.GetHDC();
::BitBlt(dc.m_hDC,0,0,rect.Width(),rect.Height(),hdc,0,0,SRCCOPY);
graphics.ReleaseHDC(hdc);
蓝边的 那个(一点宽) 是 为了说明
graphics.FillRectangle(&brush,0,0,rect.Width(),rect.Height());//
已 作用。
黑的原因是:
HBITMAP hbmp=CreateCompatibleBitmap(dc.m_hDC,rect.Width(),rect.Height());
一定不能 是 memDC !!!
::BitBlt(dc.m_hDC,0,0,rect.Width(),rect.Height(),hdc,0,0,SRCCOPY);
牵涉到 GDI 与 GDI+ 混合 编程的问题。
CPaintDC dc(this); // device context for painting
Bitmap CacheImage(90, 90);
Graphics CacheGraphics(&CacheImage );
// 对 CacheImage 进行描画
SolidBrush brush(Color(255,0,0,255));// argb
CacheGraphics.FillRectangle(&brush,0,0,90,90);//
Image image(L"3.png");
CacheGraphics.DrawImage(&image,1,1,88,88);
// 获得窗口的 Graphics 对象
Graphics Graphic(dc.m_hDC);
// 将描画好的 CacheImage 画到窗口上
Graphic.DrawImage(&CacheImage, 0, 0);
//wndcls.hbrBackground = (HBRUSH)backGrush.m_hObject;