I'm drawing text (textOut) and Rectangles on my window... and I would like to get the RGB buffer from it... How can I do it?
问问题
2563 次
1 回答
3
有2个选项:
首先,您可以使用 GetPixel()。我用了很多。它工作正常:
COLORREF GetPixel(
HDC hdc,
int nXPos,
int nYPos
);
在我们的时代,使用此功能的处理器甚至可以在某些情况下使用矩形。
其次,您可以将屏幕内容复制到位图中。之后,您可以将其放在剪贴板中,使用您的代码进行处理等。核心功能是:
BOOL BitBlt(
_In_ HDC hdcDest,
_In_ int nXDest,
_In_ int nYDest,
_In_ int nWidth,
_In_ int nHeight,
_In_ HDC hdcSrc,
_In_ int nXSrc,
_In_ int nYSrc,
_In_ DWORD dwRop
);
如果需要,我可以发布更详细的代码段。
// Pick up the DC.
HDC hDC = ::GetDC(m_control);
// Pick up the second DC.
HDC hDCMem = ::CreateCompatibleDC(hDC);
// Create the in memory bitmap.
HBITMAP hBitmap = ::CreateCompatibleBitmap(hDC, bmp_size_x, bmp_size_y);
// Put bitmat into the memory DC. This will make it functional.
HBITMAP hBmpOld = (HBITMAP)::SelectObject(hDCMem, hBitmap);
// Clear the background.
HBRUSH hBkgr = ::CreateSolidBrush(props.bkgr_brush);
RECT bitmap_rect = { 0, 0, bmp_size_x, bmp_size_y };
::FillRect(hDCMem, &bitmap_rect, hBkgr);
::DeleteObject(hBkgr);
// Do the job.
::BitBlt(hDCMem, margins_rect.left, margins_rect.top,
size_to_copy_x, size_to_copy_y, hDC,
screen_from_x, screen_from_y, SRCCOPY);
于 2012-11-11T20:39:45.500 回答