Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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]

like image 314
Joe Avatar asked Jun 17 '11 21:06

Joe


1 Answers

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:

  • 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

  • MSDN: Using a Cached Bitmap to Improve Performance
  • MSDN: CachedBitmap Class
like image 62
Ian Boyd Avatar answered Oct 23 '22 11:10

Ian Boyd