C# WinForms - 任何人都知道 C# GDI 库而不是 SLOW GDI+
GDI+ 非常慢,几乎完全是软件,而 GDI 是高度硬件加速的。 GDI+ 是 Graphics 类在 WinForms 上使用的,但它太慢了。
有没有人制作了 .NET GDI 库以便我们可以提高速度?
[编辑] 很多人推荐 OpenGL/DirectX。我的一个要求是客户端兼容性,尤其是远程桌面。 AFAIK 远程桌面不支持开箱即用的 OGL/DirectX。[/编辑]
GDI+ is very slow, almost entirely software whereas GDI is highly hardware accelerated.
GDI+ is what the Graphics class uses on WinForms and it's just too slow.
Has anyone made a .NET GDI library so we can have the speed?
[EDIT]
Many people are recommending OpenGL/DirectX. A requirement of mine is client compatibility especially remote desktop. AFAIK remote desktop does not support OGL/DirectX out of the box.[/EDIT]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
GDI+ 中的文本渲染速度比 GDI 慢。 Microsoft 在 .NET 1.1 之后意识到了这一点。
这就是为什么 .NET 2.0 包含一个新的
TextRenderer
包装 GDI 绘制文本。它有两个静态方法:TextRenderer.MeasureText
TextRenderer.DrawText
。在 .NET 2.0 中,所有 WinForm 控件都被转换为使用
TextRenderer
,而不是:(前提是您关闭关闭
UseCompatibleTextRendering
)绘制
位图
在 GDI+ 中也很慢,这就是您使用CachedBitmap
.它绘制速度非常快。另请参阅
Text rendering in GDI+ is slower than GDI. Microsoft realized this after .NET 1.1.
That is why .NET 2.0 contains a new
TextRenderer
class that wraps GDI DrawText. It has two static methods:TextRenderer.MeasureText
TextRenderer.DrawText
.In .NET 2.0, all WinForm controls were converted to use
TextRenderer
, instead of:(provided you turn off
UseCompatibleTextRendering
)Drawing a
Bitmap
is also slow in GDI+, that is why you useCachedBitmap
. It draws very speedy.See also
您检查过 SlimDX 吗?它有一个围绕 Direct2D 的托管包装器,这是一个完全硬件加速的 2d API,也与传统 GDI 很好地混合。
编辑:
我还发现您可能会感兴趣的这个库:SharpDX
“SharpDX 旨在使用作为替代托管 DirectX 框架,该 API 是从 DirectX SDK 标头自动生成的,具有 AnyCpu 目标,这意味着您可以在 x86 和 x64 平台上运行应用程序,而无需重新编译项目或将程序集安装到 GAC 中。最快的 Managed-DirectX 实施。”
这也支持 Direct2D。
Have you checked out SlimDX? It has a managed wrapper around Direct2D, which is a fully hardware accelerated 2d API and also mixes well with traditional GDI.
Edit:
I also found this library you might find interesting: SharpDX
"SharpDX is intended to be used as an alternative managed DirectX framework. The API is generated automatically from DirectX SDK headers, with AnyCpu target, meaning that you can run your application on x86 and x64 platform, without recompiling your project or installing assemblies into the GAC. SharpDX is also the fastest Managed-DirectX implementation."
This also has support for Direct2D.
您可以尝试迁移到 WPF。
我这样做是因为 WinForms 绘制速度很慢。
这种转变非常困难,尤其是对于像我这样的老式程序员来说。
但 WinForms 在启动速度和 RAM 方面无法被击败。
WPF 启动缓慢并占用大量 RAM。
You can try and move to WPF.
I did so because WinForms draw slowly.
The transition is very hard, especially for old-fashioned code-ers like me.
But WinForms cannot be beaten at startup speed and RAM.
WPF starts slowly and takes lots of RAM.
微软 API 代码包(2010 年 2 月存档)包含调用示例来自托管语言的 DirectX API。
您可以在 Nuget 上获取 WindowsAPICodePack-DirectX。
The Microsoft API Code Pack (Archived Feb. 2010) has examples of calling DirectX APIs from managed languages.
You can get WindowsAPICodePack-DirectX on Nuget.
如果您的应用程序是跨平台的,我建议使用 OpenTK,它是 OpenGL 的托管包装器,并且经常使用比 DirectX(托管的或本机的)更容易学习。 OpenTK/OpenGL 也往往比 DirectX 提供更好的性能。使用 OpenTK,您可以完全在 GPU 上绘制图像,然后将其光栅化为位图,该位图可以与 System.Drawing 中的 Bitmap 类互操作。
If your application is cross-platform, I would recommend using OpenTK, which is a managed wrapper for OpenGL, and is often easier to learn than DirectX (either managed or native). OpenTK/OpenGL tend to deliver better performance than DirectX as well. With OpenTK, you can draw your image entirely on the GPU, then rasterize it into a bitmap which can interop with the Bitmap class in System.Drawing.