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

前端 未结 2 1971
误落风尘
误落风尘 2021-02-02 07:51

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

相关标签:
2条回答
  • 2021-02-02 08:07

    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.

    0 讨论(0)
  • 2021-02-02 08:16

    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.

    0 讨论(0)
提交回复
热议问题