将System.Windows.Media.Brush转换为System.Drawing.Brush
如何将System.Windows.Media.Brush转换为System.Drawing.Brush?
我试图将system.windows.media.brush的颜色格式化为System.Drawing.Color对象。
下面的解决方案不起作用,因为它需要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 ); }
我相信你可以把它作为SolidColorBrush投射来获得颜色。
尝试以下方法:
MyColor = ((SolidColorBrush)MyMediaBrush).Color;
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);