0
votes

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

1
What's the HRESULT error you are getting? - Chuck Walbourn
@ChuckWalbourn : D3DX11SaveTextureToFile gives "Attempted to create a device with the debug layer enabled and the layer is not installed" Directx::SaveWICTextureToFile gives "No such interface supported" - arch3r
D3DX11 is deprecated and hasn't been updated in many years, so the error output is probably trying to turn E_NOINTERFACE into something meaningful which it isn't anymore. Can you tell me exactly which line of code in ScreenGrab.cpp or DirectXTexWIC.cpp where you are seeing this error generated? - Chuck Walbourn
@ChuckWalbourn : IWICImagingFactory* pWIC = _GetWIC(); is failing and the return is E_NOINTERFACE - arch3r
What OS are you using? Which vcxproj/sln file or NuGet version of DirectXTex are you using? Depending on how you build the code, _GetWIC will either try to use WIC2 and then WIC1, or just WIC1. See this post - Chuck Walbourn

1 Answers

1
votes

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.