SlimDX引发尝试Texture2D.ToStream()时发生未确定的错误

时间:2015-01-24 22:43:18

标签: c# wpf directx-11 slimdx

使用SlimDX并尝试从纹理中获取内存流。我收到错误:E_FAIL:发生未确定的错误(-2147467259)。这应该很简单,对吧?

这是我的设备声明:

`d3dDevice11 = new SlimDX.Direct3D11.Device(DriverType.Hardware, DeviceCreationFlags.Debug);

我的纹理声明:

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;
_texture = new Texture2D(d3dDevice11, textureDesc);

获得Stream的电话:

MemoryStream newMemStream = new MemoryStream();
SlimDX.Result sdxRes = SlimDX.Direct3D11.Texture2D.ToFile(
                   _texture.Device.ImmediateContext, 
                   _texture, 
                   SlimDX.Direct3D11.ImageFileFormat.Bmp, 
                   (Stream)newMemStream);

谁能说出我做错了什么?

谢谢, 道格

1 个答案:

答案 0 :(得分:0)

原来,Texture2D无法供CPU使用。创建从CPU可见的Texture2D就可以了。