开发者

Convert System.Drawing.Color to System.Windows.Media.Color [duplicate]

开发者 https://www.devze.com 2023-01-23 21:08 出处:网络
This question already has ans开发者_Go百科wers here: How to convert from System.Drawing.Color to System.Windows.Media.Color?
This question already has ans开发者_Go百科wers here: How to convert from System.Drawing.Color to System.Windows.Media.Color? (4 answers) Closed 6 years ago.
System.Drawing.Color drawRedColor = System.Drawing.Color.Red;
System.Windows.Media.Color mediaColor = ?drawRedColor.ToMediaColor();?


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.


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

精彩评论

暂无评论...
验证码 换一张
取 消