天天看點

WPF string,color,brush之間的轉換

String轉換成Color

string-"ffffff"

Color color = (Color)ColorConverter.ConvertFromString(string);

      

String轉換成Brush

BrushConverter brushConverter = new BrushConverter();
Brush brush = (Brush)brushConverter.ConvertFromString(string);      

Color轉換成Brush

Brush brush = new SolidColorBrush(color));      

Brush轉換成Color

//先将Brush轉成string,再轉成Color

 Color color= (Color)ColorConverter.ConvertFromString(brush.ToString());

//将Brush轉成SolidColorBrush,再取Color

 Color color= ((SolidColorBrush)CadColor.Background).Color;

      

(ARGB)轉換為Brush

Brush br = new SolidColorBrush(Color.FromArgb(cl.Color.A, cl.Color.R, cl.Color.G, cl.Color.B));       

轉載于:https://www.cnblogs.com/railgunman/p/6065814.html