Using SlimDX and trying to get a memory stream from a texture. I get the error: E_FAIL: An undetermined error occurred (-2147467259). This should be simple, right?
Here is my device declaration:
d3dDevice11 = new SlimDX.Direct3D11.Device(DriverType.Hardware, DeviceCreationFlags.Debug);
And my Texture declaration:
Texture2DDescription textureDesc = new Texture2DDescription();
textureDesc.BindFlags = BindFlags.ShaderResource | BindFlags.RenderTarget;
textureDesc.Format = SlimDX.DXGI.Format.B8G8R8A8_UNorm;
textureDesc.Width = _inputWidth;
textureDesc.Height = _inputHeight;
textureDesc.MipLevels = 1;
textureDesc.ArraySize = 1;
textureDesc.SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0);
textureDesc.Usage = ResourceUsage.Default;
textureDesc.OptionFlags = ResourceOptionFlags.Shared;
textureDesc.CpuAccessFlags = CpuAccessFlags.None;
textureDesc.ArraySize = 1;
Texture2D _texture = new Texture2D(d3dDevice11, textureDesc);
And the call to get the Stream:
MemoryStream newMemStream = new MemoryStream();
SlimDX.Result sdxRes = SlimDX.Direct3D11.Texture2D.ToFile(
_texture.Device.ImmediateContext,
_texture,
SlimDX.Direct3D11.ImageFileFormat.Bmp,
(Stream)newMemStream);
I have tried various combinations of things. Always the same. I tried ToFile with the same error. I have tried:
new DeviceContext(_texture.Device);
_texture.Device.ImmediateContext
new DeviceContext(_texture.Device)
new SlimDX.Direct3D11.DeviceContext(d3dDevice11)
Always the same result.
Any help would be very much appreciated!
Thanks,
Doug