【发布时间】:2015-09-12 12:16:20
【问题描述】:
我想为 C# WinForms 应用程序实现硬件加速。原因是我必须绘制 150 x 720p 的图像,而 5 个图片框控件花费的时间太长(缩放+绘制图像),因此在处理和重新加载方面存在问题。 所以我处理了ShapeDX。
但现在我卡住了,不知道如何绘制 2D 纹理。为了测试代码,我只有一个测试按钮和一个图片框。
当我在 PictureBox 中运行代码时,还会加载 DirectX(Draw 或 3D)。我承认黑色背景。 但我不明白必须如何绘制纹理。
String imageFile = "Image.JPG";
Control TargetControl = this.pictureBoxCurrentFrameL;
int TotalWidth = TargetControl.Width;
int TotalHeight = TargetControl.Height;
SharpDX.Direct3D11.Device defaultDevice = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware, SharpDX.Direct3D11.DeviceCreationFlags.Debug);
SharpDX.Toolkit.Graphics.GraphicsDevice graphicsDevice = SharpDX.Toolkit.Graphics.GraphicsDevice.New(defaultDevice);
SharpDX.Toolkit.Graphics.PresentationParameters presentationParameters = new SharpDX.Toolkit.Graphics.PresentationParameters();
presentationParameters.DeviceWindowHandle = this.pictureBoxCurrentFrameL.Handle;
presentationParameters.BackBufferWidth = TotalWidth;
presentationParameters.BackBufferHeight = TotalHeight;
SharpDX.Toolkit.Graphics.SwapChainGraphicsPresenter swapChainGraphicsPresenter = new SharpDX.Toolkit.Graphics.SwapChainGraphicsPresenter(graphicsDevice, presentationParameters);
SharpDX.Toolkit.Graphics.Texture2D texture2D = SharpDX.Toolkit.Graphics.Texture2D.Load(graphicsDevice, imageFile);
//Now i should draw. But how?
swapChainGraphicsPresenter.Present();/**/
在 Windows 10 和 SharpDX-SDK-2.6.3 上使用 Microsoft Visual Studio Community 2015(.Net 4,C# WinForm)!
感谢您的帮助。
【问题讨论】:
-
您需要多久更新一次用户界面?每秒多少次?您可能只想使用 GDI。
-
我每秒可以达到 150x 720p 帧。是 5 倍不同的来源(30 fps)。 2x 720p 视频(30 fps) 2x 720p 视频帧(带有识别模式) 1x 720p 视频帧最终结果 模式识别分为几个线程。最终计算也在单独的线程上执行。所有图像都是从不同的线程生成的,并且是异步的。
-
我今天测试了 GDI。显然,性能类似于控件。我认为使用 GDI 比控件更好。所以你可以控制绘图(例如丢帧、处置等),但我更喜欢使用 Direct Draw 。有人可以帮我解决 Direct Draw 问题吗?
-
有人知道吗?
-
如果您只绘制 2D 的东西,您应该使用 Direct2D。我很确定 SharpDX 会包装它。 DirectDraw 已被标记为已弃用大约十年。您使用它的方式与我过去的方式不同。而且它的实现也不是微不足道的,所以我不知道在这里包含我的所有代码是否合适。我会看看我能不能把东西放在一起,但可能需要一段时间。应该有一个带有 SharpDX 的 Direct2D 示例。试试看,如果您需要帮助,请告诉我。
标签: c# winforms sharpdx slimdx