简体   繁体   中英

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

我需要将System.Windows.Media.SolidcolorBrush转换为C#中的System.Drawing.Color,任何线索都会很棒。

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);
    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);
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM