5

According to MSDN's listing, GDI and GDI+ are both legacy. So when writing an application using the Windows API, what should you use to render 2d graphics?

Direct2D, WIC, DirectComposition (this is new to me), GDI+, GDI?

Note: not 2d games - just 2d images.

Josh
  • 6,046
  • 11
  • 52
  • 83
  • DirectComposition looks like it needs Windows 8, btw. That's probably why I haven't heard of it. – chris Jul 25 '12 at 23:13
  • 2
    I wouldn't worry about Microsoft's recommendations they tend to change with each flavor of the month API they release. When the day comes that .NET is labeled "legacy" GDI will still be around. – AJG85 Jul 26 '12 at 00:03
  • Related question: http://stackoverflow.com/questions/10007789/are-gdi-gdi-and-opengl-really-obsolete-deprecated – RED SOFT ADAIR Jul 26 '12 at 09:56

2 Answers2

5

Either GDI or GDI+ are fine choices for basic needs.

The OS still uses GDI all over the place, so I'm not really sure what they mean by "legacy". Words like that generally don't have a meaning, so you shouldn't feel too bad ignoring them. The person who labeled these APIs "legacy" is probably one of those people who tell you that all of Win32 is legacy without realizing that these "modern" GUI frameworks that they love so much are built on top of Win32 and wouldn't be able to function without it.

Use GDI+ if you need the extra features it provides (such as transparency, etc.) and/or if you're programming in C++ and prefer its class-based API to GDI's flat C-style API. But note that if your app uses GDI+, you will have to redistribute the Gdiplus.dll library to users running Windows 2000 and earlier versions. GDI-based apps will always work out of the box.

That's not to say that you shouldn't investigate the new contenders. Supposedly, Direct2D is designed to interoperate well with GDI and GDI+. Only problem is, lots of developers are not in a position to require all of their clients to upgrade to Windows Vista or later. Supporting XP still seems like a worthwhile goal (at least providing a minimal subset of functionality for those users), and that's not really possible if you write the entire UI in Direct2D or one of the new fancy frameworks. I haven't really seen the advantage of switching to Direct2D for standard, line-of-business apps (I'm sure there are advantages for games and other programs that need 3D effects). You might be interested in the following comparison between Direct2D and GDI, which are both two-dimensional, hardware-accelerated graphics APIs.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • I know that GDI and GDI+ are not going anyway soon and are fine to use, but MSDN has a clear definition of "legacy": `Technologies that are obsolete and should not be used in new applications.`. – Jesse Good Jul 25 '12 at 23:13
  • 2
    Should I be more clear, then, in saying that that particular MSDN entry is wrong? Or at least written by someone in the marketing department who is a bit overzealous? – Cody Gray - on strike Jul 25 '12 at 23:17
  • Well, I think we can interpret "new" to mean starting from Windows 8, as I know "GDI and GDI+ are not supported when writing Metro-style applications", so it depends on your needs. – Jesse Good Jul 25 '12 at 23:24
  • Still a bit premature, wouldn't you say? Considering Windows 8 has not even been released yet, how are customers going to run applications we write using "non-legacy" APIs? This line has been in MSDN for at least a couple of months, long before there was even a public release preview of Win 8. Besides, there is a huge class of applications that simply will not work as Metro apps. – Cody Gray - on strike Jul 25 '12 at 23:28
4

Unless you really have to support XP (let it die already!), I would highly encourage using Direct2D. There are multiple reasons why Direct2D makes sense for all new developments:

  • generally faster rendering (aliased and anti-aliased rendering)
  • since Vista was introduced, GDI is not HW accelleration is highly crippeld (due to the new drivermodel)
  • better integration with Direct3D (if you need it), DirectWrite, DirectComposition, etc.
  • better utilization of new GPU features
  • many bitmap effects pre-built-in
  • GDI is not allowed for Metro-Style apps

Therefore, I would suggest anybody, who is beginning a new application to use Direct2D instead of GDI/GDI+.

Jasper
  • 660
  • 1
  • 7
  • 19
  • 3
    Unfortunately as I know all too well there are a surprising number of users in the industry that still run XP, and private home users that refuse for various reasons to go to anything other than XP, be it hardware constraints, or what ever. All in all it just puts more strain on anyone that wants to write an application and have the broadest user base. – johnathan Dec 28 '12 at 14:39