5

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.

Fit Dev
  • 3,413
  • 3
  • 30
  • 54
  • What features in GDI+ are you missing in Direct2D? – Walt Ritscher Jul 13 '14 at 20:21
  • GDI+ is not image processing, it's just a wrapper around Win32 GDI which supports mostly for rendering UI (not images). So the features are fairly limited. I think you should search for some image Library for .NET, with such libraries you can do whatever operations (on an image) you like, such as perform some complicated Transforms, ... Graphics in WPF is much better than in Winforms, however it's also UI-oriented rather than focused on Image. – King King Jul 14 '14 at 00:12
  • @WaltRitscher Well for instance: HatchBrush, ColorMatrix, PathGradientBrush to name a few. – Fit Dev Jul 14 '14 at 10:11
  • @KingKing Right but it has quite a few extra features in addition to those of pure GDI. But you are right an image library would be a good supplement. However there are some questions then, what should be the lowest common denominator in as far as image/bitmap type for example - i.e. the one provided by the library, Drawing.Bitmap, Media.Bitmap, WIC.Bitmap; also considering the fact that direct access to pixel data via pointers is a must, and it should be possible to inexpensively convert it to other types to take advantage of other technologies like DirectText. Any library you can recommend? – Fit Dev Jul 14 '14 at 10:16

1 Answers1

1

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.

heltonbiker
  • 26,657
  • 28
  • 137
  • 252
  • Thank you for posting! However I am more concerned about image processing aspect rather than UI. For UI, I will probably transition from WinForms to WPF. However that does not really affect the image processing part, as that ideally should be UI-independent and possibly even run in the context of a Service (which neither GDI+ nor WPF can). – Fit Dev Jul 14 '14 at 10:18
  • Well, then my suggestion is even MORE in terms of not using `System.Windows.Media[.Imaging]` namespace to REPRESENT image and image content. You could have your ViewModel properties to be of any type is more convenient to you (I find arrays of doubles to be the best choice for numbercrunching), and use said namespace only to PRESENT images visually, via databinding and value converters. If you have enough knowledge, you could implement image-processing algorithms yourself, instead of depending on often limited methods provided by .Net imaging namespaces. Hope this helps! – heltonbiker Jul 14 '14 at 13:51