Joe
Joe

Reputation: 1044

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

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]

Upvotes: 17

Views: 18577

Answers (5)

Dour High Arch
Dour High Arch

Reputation: 21722

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

You can get WindowsAPICodePack-DirectX on Nuget.

Upvotes: 2

Ian Boyd
Ian Boyd

Reputation: 257085

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

Upvotes: 27

Brandon Moretz
Brandon Moretz

Reputation: 7641

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.

Upvotes: 7

bbosak
bbosak

Reputation: 5529

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.

Upvotes: 0

Vercas
Vercas

Reputation: 9161

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.

Upvotes: 2

Related Questions