获取浏览器窗口的位图

时间:2016-04-30 17:31:48

标签: c++ google-chrome firefox

有谁知道如何获取Mac和Windwos浏览器窗口的位图?我想在渲染时从Chrome或FireFox中捕获图像并将它们传递到基于C ++的插件中。

我已经考虑过使用Chrome扩展程序,但这不实用。

愿意购买Mac和Windows原生应用。

1 个答案:

答案 0 :(得分:1)

使用Windows API,您可以轻松获取屏幕截图。

// get the device context of the screen
HDC hScreenDC = CreateDC("DISPLAY", NULL, NULL, NULL);     
// and a device context to put it in
HDC hMemoryDC = CreateCompatibleDC(hScreenDC);

int width = GetDeviceCaps(hScreenDC, HORZRES);
int height = GetDeviceCaps(hScreenDC, VERTRES);

// maybe worth checking these are positive values
HBITMAP hBitmap = CreateCompatibleBitmap(hScreenDC, width, height);

// get a new bitmap
HBITMAP hOldBitmap = SelectObject(hMemoryDC, hBitmap);

BitBlt(hMemoryDC, 0, 0, width, height, hScreenDC, 0, 0, SRCCOPY);
hBitmap = SelectObject(hMemoryDC, hOldBitmap);

// clean up
DeleteDC(hMemoryDC);
DeleteDC(hScreenDC);
// now your image is held in hBitmap. You can save it or do whatever with it

我不确定浏览器的确切区域,或者如何为Mac解决它。如果不出意外,它就是一个开始。