简体   繁体   中英

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]

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM