将 System.Windows.Media.Color 转换为 System.Drawing.Color
Posted
技术标签:
【中文标题】将 System.Windows.Media.Color 转换为 System.Drawing.Color【英文标题】:Converting System.Windows.Media.Color to System.Drawing.Color 【发布时间】:2011-06-04 16:28:01 【问题描述】:private void DialogFont_Load(object sender, EventArgs e)
LoadInstalledFonts();
SetupInitialDialogSelections();
lblPreview.ForeColor = colorPicker1.colorPickerControlView1.CurrentColor.Color;
我想将该值转换为 System.Drawing.Color。
有什么想法吗?
【问题讨论】:
【参考方案1】:System.Windows.Media.Color mediacolor; // your color
var drawingcolor = System.Drawing.Color.FromArgb(
mediacolor.A, mediacolor.R, mediacolor.G, mediacolor.B);
【讨论】:
【参考方案2】:仅供参考...我用这个:
using System.Runtime.CompilerServices;
using System.Windows.Media;
namespace HQ.Wpf.Util
public static class ColorExtension
/// <summary>
/// Convert Media Color (WPF) to Drawing Color (WinForm)
/// </summary>
/// <param name="mediaColor"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static System.Drawing.Color ToDrawingColor(this System.Windows.Media.Color mediaColor)
return System.Drawing.Color.FromArgb(mediaColor.A, mediaColor.R, mediaColor.G, mediaColor.B);
/// <summary>
/// Convert Drawing Color (WPF) to Media Color (WinForm)
/// </summary>
/// <param name="drawingColor"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static System.Windows.Media.Color ToMediaColor(this System.Drawing.Color drawingColor)
return System.Windows.Media.Color.FromArgb(drawingColor.A, drawingColor.R, drawingColor.G, drawingColor.B);
【讨论】:
以上是关于将 System.Windows.Media.Color 转换为 System.Drawing.Color的主要内容,如果未能解决你的问题,请参考以下文章
Javascript 将正则表达式 \\n 替换为 \n,将 \\t 替换为 \t,将 \\r 替换为 \r 等等