VC中如何把一个内存设备环境中的位图复制到另一个内存设备环境中?
自制了一个倒计时窗口类控件,在OnPaint函数中使用GDI+的DrawImage函数绘制背景图。150毫秒通过Invalidate函数发送WM_PAINT消息刷新屏幕。但实际运行过程中发现,每次通过DrawImage函数绘制控件窗口的背景太占CPU(4%,电脑室4核芯片),于是定义了一个初始化函数Init,在初始化函数中将背景预先绘制到一个内存设备区域,然后在OnPaint中将该内存设备环境中的内容复制到当前的内存设备环境中。但无法实现。求指教。
void CCountDClock::Init()
{
m_pDc = new CDC;//m_pDC是控件类CCountDClock的成员变量,类型为CDC*
m_pDc->CreateCompatibleDC(NULL);
CBitmap bmp;
bmp.CreateCompatibleBitmap(m_pDc, rect.Width(), rect.Height());
m_pDc->SelectObject(&bmp);
Graphics graphics(m_pDc->GetSafeHdc());
Image image_bckground(TEXT(".\\res\\student_background.png"));
graphics.SetSmoothingMode(SmoothingModeAntiAlias);
bmp.DeleteObject();
}
void CCountDClock::OnPaint()
{
// TODO: Add your message handler code here
// Do not call CWnd::OnPaint() for painting messages
CPaintDC dc(this);
CDC memdc;
CBitmap bmp;
CRect rc;
int nWidth, nHeight;
CFont m_font1;
CFont m_font2;
memdc.CreateCompatibleDC(&dc);
GetClientRect(&rc);
nWidth = rc.Width();nHeight = rc.Height();
int nClock_width, nClock_height,nClockcenter_width, nClockcenter_height;
bmp.CreateCompatibleBitmap(&dc, nWidth, nHeight);
memdc.SelectObject(&bmp);
memdc.FillSolidRect(rc,RGB(0,0,0));
memdc.SetBkMode(TRANSPARENT);
Graphics graphics(memdc.GetSafeHdc());
// Image image_bckground(TEXT(".\\res\\student_background.png"));
memdc.BitBlt(0, 0, rc.Width(), rc.Height(), m_pDc, 0, 0, SRCCOPY);//此处想把之前的m_pDC指向的内存设备复制到memdc中,但没有成功
Image image_clockframe(TEXT(".\\res\\alarm_empty.png"));
nClock_width = image_clockframe.GetWidth();
nClock_height = image_clockframe.GetHeight();
// graphics.SetSmoothingMode(SmoothingModeAntiAlias);
// graphics.DrawImage(&image_bckground, 0, 0, nWidth, nHeight);//原来的绘图函数由于绘制频率较高,太占用CPU
.................................
}
...全文
相关推荐
根据CDC内存中的内容,生成黑白点阵的位图的VC源码
VC源码,根据CDC内存中的内容,生成黑白点阵的位图,适用于条码生成打印,光刻机WMF文件,LED屏显等
VC6环境下动态位图加载与管理技术详解
Win32 API(Application Programming Interface),即32位Windows应用程序编程接口,是微软Windows操作系统的一套核心编程接口。自从1993年Windows NT 3.1发布以来,Win32 API已经成为Windows平台开发的基础。Win32 API具有以下特点:底层性:作为操作系统的基础接口,它允许开发者直接与操作系统底层进行交互。庞大性。
vc中如何显示位图vc中如何显示位图vc中如何显示位图
vc中如何显示位图vc中如何显示位图vc中如何显示位图vc中如何显示位图vc中如何显示位图
VC打印位图,VC+MapX打印地图
VC打印位图,VC+MapX打印地图功能,没有用GDI+。只需要把我的打印方法拷贝到你的类中就能直接运行了,非常简单。
VC实现默认打印机打印位图
VC实现默认打印机打印位图,再别人的基础上改进,通过运行测试的。


界面
