Convert System.Drawing.Color to System.Windows.Med

2019-01-23 11:51发布

This question already has an answer here:

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

2条回答
别忘想泡老子
2楼-- · 2019-01-23 12:27

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.

查看更多
混吃等死
3楼-- · 2019-01-23 12:38
System.Windows.Media.Color mediaColor = System.Windows.Media.Color.FromRgb(Color.Red.R, Color.Red.G, Color.Red.B);
查看更多
登录 后发表回答