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

喜夏-厌秋 提交于 2019-11-28 07:58:43

问题


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

I'm trying to get the color of a system.windows.media.brush formatted to a System.Drawing.Color object.

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:

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

回答1:


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

Try something like:

MyColor = ((SolidColorBrush)MyMediaBrush).Color;



回答2:


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


来源:https://stackoverflow.com/questions/1046301/convert-system-windows-media-brush-to-system-drawing-brush

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!