Reputation: 56
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
Upvotes: 0
Views: 1721
Reputation: 212
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.
Upvotes: 1