【问题标题】:SlimDX Throws An undetermined error occurred when trying Texture2D.ToStream()SlimDX 在尝试 Texture2D.ToStream() 时抛出未确定的错误
【发布时间】:2015-01-24 22:43:17
【问题描述】:

使用 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);

谁能告诉我我做错了什么?

谢谢, 道格

【问题讨论】:

    标签: c# wpf directx-11 slimdx


    【解决方案1】:

    原来 Texture2D 对 CPU 不可用。创建一个从 CPU 可见的 Texture2D 就可以了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-04
      • 1970-01-01
      • 1970-01-01
      • 2018-03-25
      • 1970-01-01
      • 2021-11-25
      相关资源
      最近更新 更多