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

Joe picture Joe · Jun 17, 2011 · Viewed 16k times · Source

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]

Answer

Ian Boyd picture Ian Boyd · Jun 25, 2011

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