VC中如何把一个内存设备环境中的位图复制到另一个内存设备环境中?

chiweiyong chiweiyong 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
自制了一个倒计时窗口类控件,在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
.................................
}

...全文

相关推荐

评论 12
收藏 已收藏
分享
返回顶部
chiweiyong
界面 15,977 成员 115,865 内容