Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Drawing (GDI+) vs System.Windows.Media (WPF) vs Direct2D+DirectWrite+WIC

For a Desktop Vista+ application that processes images, and is to be written in C#, which of the following technologies (or combinations_ would you recommend: System.Drawing (GDI+) vs System.Windows.Media vs Direct2D+DirectWrite+WIC. Image Processing will involve all kinds of primitive drawing, filling, working with text, rotations, translations, scaling, working with pixel data directly using pointers. In general, how good the above technologies work for manipulating bitmaps?

Also, if anyone knows of a good and detailed comparison chart that lists side-by-side different features and equivalents, as well as what is not supported, that would be great! For example, are there ColorMatrix equivalents in WPF and Direct2D? After investigating SharpDX's implementation of Direct2D, for instance, I was left with the impression that even though Microsoft positions it as a complete alternative to GDI+, I could not find all GDI+'s functionality in Direct2D.

Also, considering that it's 2014, would you say that at least for image manipulation (if not the UI part of things, where WPF seems to be a far better choice), GDI+ would be ok for the next 5 or so years? Or should I really consider using all 3 technologies where each works best?

Thank you.

like image 630
Fit Dev Avatar asked Nov 11 '22 05:11

Fit Dev


1 Answers

I currently work in a visual-intensive C#/WPF project, and have done some hobbyst hacking with image processing in Python.

With your intended use, I would use the following approach:

  • Use WPF namespaces as much as possible, that is, System.Windows.Media. As far as I know, System.Drawing and GDI+ in general use unmanaged resources, and that could create undesired, avoidable problems;
  • Use, as strictly as possible, the MVVM architecture. That is, you have a View layer used only to display information, and Model and ViewModel layers that contain business logic. Although some might say that visual stuff don't belong to ViewModel layer, if your application deals with manipulation of images then your Business Logic is View-related by definition (it took me a long time to figured this out).
  • When in doubt, perform Image-Processing using multidimensional arrays (in the Model/ViewModel) and bind those arrays to the View (via DataBinding using a ValueConverter).

That way, for example, you could have an ImageLayerViewModel class to represent a Layer, with a Data property (or Value or PixelArray or Raster, whatever) being a double[height,width,depth].

I could elaborate some more, but I'm not sure to be in the right track to answer your question, so write any comment if you want.

like image 115
heltonbiker Avatar answered Nov 15 '22 08:11

heltonbiker