将System.Drawing.Color转换为System.Windows.Media.Color

时间:2010-11-05 10:00:48

标签: .net system.drawing system.windows.media

System.Drawing.Color drawRedColor = System.Drawing.Color.Red;
System.Windows.Media.Color mediaColor = ?drawRedColor.ToMediaColor();?

2 个答案:

答案 0 :(得分:47)

怎么样:

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);
}

编辑:修正了ARGB的'拆包'。

答案 1 :(得分:7)

System.Windows.Media.Color mediaColor = System.Windows.Media.Color.FromRgb(Color.Red.R, Color.Red.G, Color.Red.B);