应用程序窗口截屏有空白输出 [英] Application window screen capture has blank output
问题描述
我正在尝试屏幕捕获应用程序窗口的内容,类似于Alt-PrintScreen键盘快捷键。
对于大多数应用程序窗口,它工作正常。但是,对于某些应用程序,结果为空白输出。
相关代码:
const int height = 1000;
const int width = 1000;
const wchar_t * windowTitle = L" MEmu 2.8.6-MEmu" ;;
HWND hwndSrc = FindWindowEx(0,0,0,windowTitle);
HDC hdcSrc = GetWindowDC(hwndSrc);
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd,& ps);
BitBlt(hdc,0,0,width,height,hdcSrc,0,0,SRCCOPY);
EndPaint(hWnd,& ps);
预期产量:
i.imgur.com/23bcC0Z.png
实际输出:
i.imgur.com/chYb9g2.png
$
为什么它不能用于某些窗口?
尝试组合标志: SRCCOPY | CAPTUREBLT 。还要考虑替代方案,例如
PrintWindow 函数,Direct3d等:
https://blogs.msdn.microsoft.com/dsui_team/2013/03/25/ways-to-capture-the-screen
I am trying to screen capture an application window's contents, similar to the Alt-PrintScreen keyboard shortcut.
For most application windows, it works fine. However, for some applications, the result has blank output.
Relevant code:
const int height = 1000; const int width = 1000; const wchar_t *windowTitle = L"MEmu 2.8.6 - MEmu"; HWND hwndSrc = FindWindowEx(0, 0, 0, windowTitle); HDC hdcSrc = GetWindowDC(hwndSrc); PAINTSTRUCT ps; HDC hdc = BeginPaint(hWnd, &ps); BitBlt(hdc, 0, 0, width, height, hdcSrc, 0, 0, SRCCOPY); EndPaint(hWnd, &ps);
Expected output:
i.imgur.com/23bcC0Z.png
Actual output:
i.imgur.com/chYb9g2.png
Why is it not working for some windows?
Try a combination of flags: SRCCOPY | CAPTUREBLT. Also consider the alternatives, such as the PrintWindow function, Direct3d, etc.: https://blogs.msdn.microsoft.com/dsui_team/2013/03/25/ways-to-capture-the-screen.
这篇关于应用程序窗口截屏有空白输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!