In SharpDX/SlimDX, I need to be able to render my image onto a Texture2D object rather than to the screen, then convert the texture into a Bitmap object.
If someone could PLEASE tell me how to do this, that would be great (with source code is even better), because I feel like I've tried everything! Here's what I've done so far, and what's going wrong:
I've set it up to render as normal, and then I've tried calling each of the following:
- RenderTargetView.ResourceAs<Texture2D>
- Texture2D.FromSwapChain<Texture2D>
Each of these successfully returns a Texture2D object, so I'm not sure if it even matters which one I use as long as I can get one to work.
However, then I call the constructor for ShaderResourceView, with the Texture2D as a parameter, and a device (which I verified works correctly), and I get an error that says there's an incorrect parameter (DIERR_INVALIDPARAM) but it doesn't say what parameter is incorrect or in what way.
I compared the description of the Texture2D returned from either of the above functions to one that I manually create when making a Texture2D from a Bitmap (which works correctly). Both functions create an identical TextureDescription, but the BindFlags are different from the one I manually create. The one I manually make I set to ShaderResource, but the one that's returned from either of the above functions sets it to RenderTarget.
Is this likely to be causing the problem, and if so, how can it be fixed? If not, what is likely the problem?
I have tried changing the BindFlags after the texture is returned to me, but the variable is read only!
What should I do? Thank you.