C# WinForms - Anyone know of a C# GDI library not SLOW GDI+

你说的曾经没有我的故事 提交于 2019-11-28 16:45:30

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:

In .NET 2.0, all WinForm controls were converted to use TextRenderer, instead of:

  • Graphics.MeasureString
  • Graphics.DrawString

(provided you turn off UseCompatibleTextRendering)


Drawing a Bitmap is also slow in GDI+, that is why you use CachedBitmap. It draws very speedy.

A CachedBitmap object stores a bitmap in a format that is optimized for display on a particular device. To display a cached bitmap, call the Graphics::DrawCachedBitmap method.

graphics.DrawCachedBitmap(bitmap, 0, 0);

See also

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.

Dour High Arch

The Microsoft API Code Pack (Archived Feb. 2010) has examples of calling DirectX APIs from managed languages.

You can get WindowsAPICodePack-DirectX on Nuget.

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.

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!