Convert System.Windows.Media.Brush to System.Drawing.Brush

How can I convert System.Windows.Media.Brush to System.Drawing.Brush?

I am trying to get the color system.windows.media.brush formatted in a System.Drawing.Color object.

The solution below does not work because it requires a solidcolorbrush object, whereas the object I need to convert is the system.windows.media.brush object:

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 ); } 
+5
c #
source share
2 answers

I believe that you can just pass it as a SolidColorBrush to get the color.

Try something like:

 MyColor = ((SolidColorBrush)MyMediaBrush).Color; 
+13
source share
  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); 
0
source share

All Articles