简体   繁体   中英

How to extract bitmap out of Direct3D 11 Texture2D object?

I am using the Desktop Duplication API (C++) and have created an output duplication object and further queried the interface for a ID3D11Texture2D object.

I have tried using "D3DX11SaveTextureToFile" and "DirectX::SaveWICTextureToFile" but it gives an error. I need to extract the bitmap or pixel buffer out of this texture so that I can save it as an image. I have tried using a subresource and ID3D11DeviceContext::Map function to extract the pixel buffer but it seems to be empty. But context->Draw() seems to work.

Is there anyway I can extract the pixel buffer/bitmap/image out of the texture2D object?

Thanks!

UPDATE : I solved this using the CaptureTexture function in DirectXTex. You can create a HBITMAP from the resultant ScratchImage

For those who are getting E_NOINTERFACE as their return code from DirectX::SaveWICTextureToFile , you need to initialize COM using one of the following:

HRESULT hr = CoInitialize(nullptr); // Single threaded

HRESULT hr = CoInitializeEx(nullptr, COINITBASE_MULTITHREADED);  // For multithreaded programs

Don't forget to call CoUninialize() after you are done. This is because WIC uses COM and must be initialized before using it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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