0

如何从 CPaintDC 图像(屏幕)到 Cimage?

CPaintDC dc(this);

dc.FillSolidRect( 20-1, 200+1, 200*3, 400+2, (COLORREF) 0x0 );

dc.SelectObject(pen1);

dc.MoveTo(20,400);
for(int i = 0;i<200;i++)
{
     dc.LineTo(20 + x[i], 600 - y1[i]);
     dc.FillSolidRect( 20 + x[i]-1,600- y1[i]-1, 3, 3, (COLORREF) 0xff00 );
}

(下面会输出一条警告消息,说明它触发了关于“dbgrptt.c - 调试 CRT 报告功能”的断点???所以我一定是错过了或做错了什么?

CImage myimage;

    myimage.GetDC();
    myimage.Save("C:\\Projects_example\\sweep.jpg");
    myimage.ReleaseDC();
4

1 回答 1

1
CRect rc;
GetClientRect(rc);
CImage myimage;
myimage.Create(rc.Width(), rc.Height(), 24);
CDC memdc;
memdc.CreateCompatibleDC(&dc);
CBitmap * pOldBitmap = memdc.SelectObject(CBitmap::FromHandle((HBITMAP)myimage));
memdc.BitBlt(0, 0, rc.Width(), rc.Height(), &dc, 0, 0, SRCCOPY);
memdc.SelectObject(pOldBitmap);

此时,您的myimage对象应该具有在dc.

于 2013-01-09T21:33:08.080 回答