简体   繁体   English

C ++中的D3D11屏幕捕获

[英]D3D11 Screen Capture in C++

Is it possible to make a screen capture of a DirectX application (game for exemple) in D3D11 ? 是否可以在D3D11中进行DirectX应用程序(例如游戏)的屏幕截图?

I can do it easily in DirectX 9 or with API hooking (IDXGISwapChain::Present), but impossible with DirectX 11. 我可以在DirectX 9或API挂钩(IDXGISwapChain :: Present)中轻松完成,但DirectX 11无法实现。

I initalize D3D11 and create the SwapChain with the Game window (FindWindow()), then I get the BackBuffer, 我初始化D3D11并使用Game窗口创建SwapChain(FindWindow()),然后我得到BackBuffer,

then ID3D11Texture2D::GetDesc() to use it in ID3D11Device::CreateTexture2D(), then ID3D11DeviceContext::CopyResource() which gives me a new ID3D11Texture2D resource. 然后是ID3D11Texture2D :: GetDesc()以在ID3D11Device :: CreateTexture2D()中使用它,然后是ID3D11DeviceContext :: CopyResource(),这为我提供了新的ID3D11Texture2D资源。

When I save it with usual ways like D3DX11SaveTextureToFile(), I always get a Black image. 当我用D3DX11SaveTextureToFile()这样的常规方法保存它时,我总是得到一个黑色图像。

What did I forget ? 我忘记了什么?

Thanks. 谢谢。

I think here are two-step to check your code: 我认为这是检查代码的两步:

  1. ID3D11DeviceContext::CopyResource() does it work as expected? ID3D11DeviceContext :: CopyResource()是否按预期工作? As we know, this func require strictly same desc of src and des, is src tex have some diff desc from des tex. 众所周知,此函数要求src和des严格相同的desc,因为src tex与des tex有一些区别。 you can output to a window directly to check before you save. 您可以在保存之前直接输出到窗口进行检查。

  2. D3DX11SaveTextureToFile is deprecated, which is replaced by SaveToXXXFile (where XXX is WIC, DDS, or TGA; WIC doesn't support DDS and TGA; D3DX 9 supported TGA as a common art source format for games). 不推荐使用D3DX11SaveTextureToFile,而由SaveToXXXFile(其中XXX是WIC,DDS或TGA; WIC不支持DDS和TGA; D3DX 9支持TGA作为游戏的通用美术源格式)取代。 DirectXTex and DirectXTK library is new. DirectXTex和DirectXTK库是新的。 But it still works now if you config appropriate. 但是如果配置合适,它现在仍然有用。 check this func return value. 检查此func返回值。 Make sure you do know how to use 确保您知道如何使用

     HRESULT D3DX11SaveTextureToFile( ID3D11DeviceContext *pContext, _In_ ID3D11Resource *pSrcTexture, _In_ D3DX11_IMAGE_FILE_FORMAT DestFormat, _In_ LPCTSTR pDestFile ); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM