Kaya
Kaya

Reputation: 505

How do I convert System.Windows.Media.SolidcolorBrush to System.Drawing.Color?

I need to convert a System.Windows.Media.SolidcolorBrush to a System.Drawing.Color in C# any clues would be great.

Upvotes: 11

Views: 20107

Answers (2)

ChrisF
ChrisF

Reputation: 137108

You can use SolidColorBrush.Color to get or set the colour. This is a System.Windows.Media.Color which has A, R, G, B properties.

You can then use those values when creating your System.Drawing.Color

System.Drawing.Color myColor = System.Drawing.Color.FromArgb(mediaColor.Color.A,
                                                             mediaColor.Color.R,
                                                             mediaColor.Color.G,
                                                             mediaColor.Color.B);

Upvotes: 19

Nir
Nir

Reputation: 29584

    private System.Drawing.Color WpfBrushToDrawingColor(System.Windows.Media.SolidColorBrush br)
    {
        return System.Drawing.Color.FromArgb(
            br.Color.A,
            br.Color.R,
            br.Color.G,
            br.Color.B);
    }

Upvotes: 3

Related Questions