在directx 11中渲染h264video帧

我是DirectX新手。 我正在尝试编写一个自定义IP摄像机video播放器,我正在使用DirectX11以Wpf Gui作为我的前端渲染解码图像。

我是一个c#开发人员 ,并使用了托管的directx,不再由microsoft更新,因此转移到wpf和directx11。

我的应用程序的所有部分直到帧的渲染工作正常。

我已经设法创建了一个D3DImage源,它将在Wpf应用程序中使用,成功创建我的视口和我的设备,包括我的共享资源,因为D3DImage仅适用于Directx9。 我使用SharpDX作为DirectX API的包装器。

现在我的问题是我似乎无法找到一种方法来创建纹理/从解码的图像字节更新纹理,或者这样做的正确方法是从接收的字节渲染解码图像。

任何有关这方面的帮助都会很棒,或者有人可以指导我如何接近这个方向的正确方向?

谢谢。

经过将近2周的搜索并试图找到我所述问题的解决方案,我终于找到了如下。

但是,这确实显示了图像但不是预期的,但我相信这对我来说是一个开始,因为下面的代码回答了我最初提出的问题。

 Device.ImmediateContext.ClearRenderTargetView(this.m_RenderTargetView, Color4.Black); Texture2DDescription colordesc = new Texture2DDescription { BindFlags = BindFlags.ShaderResource, Format = m_PixelFormat, Width = iWidth, Height = iHeight, MipLevels = 1, SampleDescription = new SampleDescription(1, 0), Usage = ResourceUsage.Dynamic, OptionFlags = ResourceOptionFlags.None, CpuAccessFlags = CpuAccessFlags.Write, ArraySize = 1 }; Texture2D newFrameTexture = new Texture2D(this.Device, colordesc); DataStream dtStream = null; DataBox dBox = Device.ImmediateContext.MapSubresource(newFrameTexture, 0, MapMode.WriteDiscard, 0, out dtStream); if (dtStream != null) { int iRowPitch = dBox.RowPitch; for (int iHeightIndex = 0; iHeightIndex < iHeight; iHeightIndex++) { //Copy the image bytes to Texture dtStream.Position = iHeightIndex * iRowPitch; Marshal.Copy(decodedData, iHeightIndex * iWidth * 4, new IntPtr(dtStream.DataPointer.ToInt64() + iHeightIndex * iRowPitch), iWidth * 4); } } Device.ImmediateContext.UnmapSubresource(newFrameTexture, 0); Device.ImmediateContext.CopySubresourceRegion(newFrameTexture, 0, null, this.RenderTarget, 0); var shaderRescVw = new ShaderResourceView(this.Device, this.RenderTarget); Device.ImmediateContext.PixelShader.SetShaderResource(0, shaderRescVw); Device.ImmediateContext.Draw(6, 0); Device.ImmediateContext.Flush(); this.D3DSurface.InvalidateD3DImage(); Disposer.SafeDispose(ref newFrameTexture); 

使用上面的代码,我现在能够使用我收到的新图像数据填充纹理,但图像没有以正确的颜色/像素呈现,如下图中红色框所示。

渲染图像的屏幕截图: 在此处输入图像描述

通过BGRA32像素格式的解码器接收图像字节。 任何解决这个问题的建议都会非常有帮助。