Convert System.Drawing.Color to System.Windows.Media.Color

serhio picture serhio · Nov 5, 2010 · Viewed 26.4k times · Source
System.Drawing.Color drawRedColor = System.Drawing.Color.Red;
System.Windows.Media.Color mediaColor = ?drawRedColor.ToMediaColor();?

Answer

Ani picture Ani · Nov 5, 2010

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.