30
System.Drawing.Color drawRedColor = System.Drawing.Color.Red;
System.Windows.Media.Color mediaColor = ?drawRedColor.ToMediaColor();?
Ash Burlaczenko
  • 23,106
  • 15
  • 65
  • 96
serhio
  • 27,402
  • 58
  • 213
  • 366

2 Answers2

56

How about:

using MColor = System.Windows.Media.Color;
using DColor = System.Drawing.Color;
...

public static MColor ToMediaColor(this DColor color)
{
   return MColor.FromArgb(color.A, color.R, color.G, color.B);
}

EDIT: Fixed the 'unpacking' of the ARGB.

Ani
  • 107,182
  • 23
  • 252
  • 300
7
System.Windows.Media.Color mediaColor = System.Windows.Media.Color.FromRgb(Color.Red.R, Color.Red.G, Color.Red.B);
Kell
  • 3,167
  • 18
  • 19
  • not correct approach, I don't need to transform the *Red* color, but a color variable :) – serhio Nov 05 '10 at 10:22
  • 6
    hmmm... maybe you should extrapolate on the answer as I extrapolated on the "question" :) – Kell Nov 05 '10 at 17:34