Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between System.Drawing.Color and System.Windows.Media.Color?

Tags:

.net

Basically, why the need for two abstractions of a pretty simple concept?

like image 749
moswald Avatar asked Mar 11 '10 21:03

moswald


2 Answers

System.Windows.Media.Color is part of the System.Windows.Media namespace:

Provides types that enable integration of rich media, including drawings, text, and audio/video content in Windows Presentation Foundation (WPF) applications.

System.Drawing.Color is part of the System.Drawing namespace:

The System.Drawing namespace provides access to GDI+ basic graphics functionality. More advanced functionality is provided in the System.Drawing.Drawing2D, System.Drawing.Imaging, and System.Drawing.Text namespaces.

I'm guessing that the latter is Windows specific, whilst the former is more general and is more easily portable to Mac OS etc. for use in Silverlight applications.

There is also this caution on the latter namespace which would tend to support this:

Classes within the System.Drawing namespace are not supported for use within a Windows or ASP.NET service. Attempting to use these classes from within one of these application types may produce unexpected problems, such as diminished service performance and run-time exceptions.

like image 190
ChrisF Avatar answered Oct 24 '22 12:10

ChrisF


I don't think there was a "need" as such, just that they made an early (probably wrong) decision to put the Color class into the the WinForms-specific System.Drawing - because at the time, Win32 and Winforms was all there was.

Later when they wanted to enhance the concepts in "Color", they didn't want WPF to depend on WinForms. So rather than fix the situation by moving a more abstract Color class to a generic assembly, they just copy-pasted a new Color class in WPF.

like image 34
O'Rooney Avatar answered Oct 24 '22 11:10

O'Rooney