C# 将 System.Windows.Media.Brush 转换为 System.Drawing.Brush
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1046301/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert System.Windows.Media.Brush to System.Drawing.Brush
提问by stormist
How can I convert a System.Windows.Media.Brush to System.Drawing.Brush?
如何将 System.Windows.Media.Brush 转换为 System.Drawing.Brush?
I'm trying to get the color of a system.windows.media.brush formatted to a System.Drawing.Color object.
我正在尝试获取格式化为 System.Drawing.Color 对象的 system.windows.media.brush 的颜色。
The below solution doesn't work because it requires a solidcolorbrush object, whereas the object i need converting from is a system.windows.media.brush object:
下面的解决方案不起作用,因为它需要一个 solidcolorbrush 对象,而我需要转换的对象是 system.windows.media.brush 对象:
public System.Drawing.Color GetColor( System.Windows.Media.SolidColorBrush oBrush )
{
return System.Drawing.Color.FromArgb( oBrush.Color.A,
oBrush.Color.R,
oBrush.Color.G,
oBrush.Color.B );
}
采纳答案by stevosaurus
I believe you can just cast it as a SolidColorBrush to get the color.
我相信您可以将其转换为 SolidColorBrush 来获取颜色。
Try something like:
尝试类似:
MyColor = ((SolidColorBrush)MyMediaBrush).Color;
回答by Quoc Nguyen
System.Drawing.Color c1 = new System.Drawing.Color();
c1 = System.Drawing.Color.FromName(Properties.Settings.Default.myColor);
System.Windows.Media.Color c2 = new Color();
c2 = Color.FromArgb(c1.A, c1.R, c1.G, c1.B);