在Windows中执行全屏抓取 [英] Performing full screen grab in windows

查看:136
本文介绍了在Windows中执行全屏抓取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个想法,涉及到完全捕获屏幕,包括窗口和应用程序,分析它,然后将项目绘制到屏幕上,作为覆盖。

I am working on an idea that involves getting a full capture of the screen including windows and apps, analyzing it, and then drawing items back onto the screen, as an overlay.

我想学习图像处理技术,如果我可以直接访问Windows屏幕,我可以得到大量的数据。我可以使用这个来构建自动化工具,喜欢从来没有见过。

I want to learn image processing techniques and I could get lots of data to work with if I can directly access the Windows screen. I could use this to build automation tools the likes of which have never been seen before. More on that later.

我有全屏捕获大部分工作。

I have full screen capture working for the most part.

HWND hwind = GetDesktopWindow();
HDC hdc = GetDC(hwind);

int resx = GetSystemMetrics(SM_CXSCREEN);
int resy = GetSystemMetrics(SM_CYSCREEN);
int BitsPerPixel = GetDeviceCaps(hdc,BITSPIXEL);
HDC hdc2 = CreateCompatibleDC(hdc);

BITMAPINFO info;
info.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
info.bmiHeader.biWidth = resx;
info.bmiHeader.biHeight = resy;
info.bmiHeader.biPlanes = 1;
info.bmiHeader.biBitCount  = BitsPerPixel;
info.bmiHeader.biCompression = BI_RGB;

void *data;
hbitmap = CreateDIBSection(hdc2,&info,DIB_RGB_COLORS,(void**)&data,0,0);
SelectObject(hdc2,hbitmap);

完成后,我可以反复调用:

Once this is done, I can call this repeatedly:

BitBlt(hdc2,0,0,resx,resy,hdc,0,0,SRCCOPY);

清理代码(我不知道这是否正确):

The cleanup code (I have no idea if this is correct):

DeleteObject(hbitmap);
ReleaseDC(hwind,hdc);
if (hdc2) {
    DeleteDC(hdc2);
}

每次调用BitBlt时,它会抓取屏幕并将其保存在内存中访问数据

Every time BitBlt is called it grabs the screen and saves it in memory I can access thru data.

性能有点令人满意。 BitBlt在1920x1200x32的50毫秒(有时低至33毫秒)执行。

Performance is somewhat satisfactory. BitBlt executes in 50 milliseconds (sometimes as low as 33ms) at 1920x1200x32.

令我惊讶的是,当我将显示模式切换为16位,1920x1200x16,设置,或者通过使用 ChangeDisplaySettings ,我得到一个大大提高的屏幕抓取时间在1ms和2ms之间,这不能解释为两个比特深度减少的因素。使用 CreateDIBSection (如上所述)在16位模式下提供了显着的加速,相比之下,如果我设置 CreateCompatibleBitmap (6-7ms / f)。

What surprises me is that when I switch display mode to 16 bit, 1920x1200x16, either through my graphics settings beforehand, or by using ChangeDisplaySettings, I get a massively improved screen grab time between 1ms and 2ms, which cannot be explained by the factor of two reduction in bit-depth. Using CreateDIBSection (as above) offers a significant speed up when in 16-bit mode, compared to if I set up with CreateCompatibleBitmap (6-7ms/f).

有人知道为什么要降低到16位会导致这样的速度增加吗?有没有希望我在这样的速度抓住32位?如果不是为了颜色深度,而是为了不强制改变屏幕缓冲模式和可怕的闪烁。

Does anybody know why dropping to 16bit causes such a speed increase? Is there any hope for me to grab 32bit at such speeds? if not for the color depth, but for not forcing a change of screen buffer modes and the awful flickering.

推荐答案

我解决了关于切换到16位彩色模式的令人难以置信的加速的原始问题。原来是导致Aero主题被禁用,这占了它的大部分。与航空关闭在32位,它只是大约一样快。

I solved my original question about the incredible speed up of switching to 16 bit color mode. Turns out it was causing the Aero theme to be disabled, which accounts for most of it. With Aero off in 32bit it is just about as fast.

链接到其他主题并获得良好答案。

Link to other topic with a good answer.

这篇关于在Windows中执行全屏抓取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆