gpt4 book ai didi

c++ - MFC 将部分屏幕复制到 CBitmap 中

转载 作者:太空狗 更新时间:2023-10-29 21:15:30 26 4
gpt4 key购买 nike

使用函数

OnEraseBkgnd(CDC* pDC)

我在 CDialog 派生类上写了一个填满屏幕的背景图像。

然后在 OnPaint 中,我有以下仅执行一次的代码(第一次调用 OnPaint)。

    GetInfoBarRect(&m_InfoBarRect);
m_InfoBarBGBitmap.CreateCompatibleBitmap(&dc, m_InfoBarRect.Width(), m_InfoBarRect.Height() );

bdc.CreateCompatibleDC(&dc);
pOldBitmap = bdc.SelectObject(&m_InfoBarBGBitmap);

bdc.BitBlt (m_InfoBarRect.left, m_InfoBarRect.top, m_InfoBarRect.Width(),m_InfoBarRect.Height(), &dc, 0, 0, SRCCOPY);



CImage image;
image.Attach(m_InfoBarBGBitmap);
image.Save(_T("C:\\test.bmp"), Gdiplus::ImageFormatBMP);

bdc.SelectObject(pOldBitmap);
bdc.DeleteDC();

以上代码,将屏幕的m_InfoBarRect部分复制到内存CBitmap中。

没有背景图像的一部分,我只得到一个尺寸正确的空白填充矩形。

我的代码有问题吗?

最佳答案

你从错误的坐标到错误的坐标。你的电话应该是

bdc.BitBlt( 0, 0, m_InfoBarRect.Width(), m_InfoBarRect.Height(), &dc,
m_InfoBarRect.left, m_InfoBarRect.top, SRCCOPY);

相反,即从正确的源位置 (m_InfoBarRect.left/m_InfoBarRect.top) 到目标位置 (0/0)。这是假设 GetInfoBarRect() 从与源 DC 相同的坐标系返回坐标。

关于c++ - MFC 将部分屏幕复制到 CBitmap 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37621305/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com