[英]How to get Pixel data \ Pixel buffer from a window and extract RGB?
我正在我的窗口上繪制文本 (textOut) 和矩形……我想從中獲取 RGB 緩沖區……我該怎么做?
有2個選項:
首先,您可以使用 GetPixel()。 我用了很多。 它工作正常:
COLORREF GetPixel(
HDC hdc,
int nXPos,
int nYPos
);
在我們的日子里,即使是使用此功能的 rect 處理器也可能在某些情況下起作用。
其次,您可以將屏幕內容復制到位圖。 之后,您可以將其放入剪貼板,使用您的代碼進行處理等。那里的核心功能是:
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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.