//color转为brush:
Brush br = new SolidColorBrush(Color.FromRgb(0,0,0));
//string转Color
(Color)ColorConverter.ConvertFromString((string)str);
//color转为brush:
Brush br = new SolidColorBrush(Color.FromRgb(0,0,0));
//string转Color
(Color)ColorConverter.ConvertFromString((string)str);[csharp] view plaincopyprint?//Color转string((Color)value).ToString();
string和Brush的转换
Brush color = newSolidColorBrush((Color)ColorConverter.ConvertFromString((string)str));
//Color转string((Color)value).ToString();
string和Brush的转换
Brush color = newSolidColorBrush((Color)ColorConverter.ConvertFromString((string)str)); [csharp] view plaincopyprint?//Brush转string
//Brush转string[csharp] view plaincopyprint?((Brush)value).ToString();
//string转byte[]
System.Text.UnicodeEncoding converter = newSystem.Text.UnicodeEncoding();
((Brush)value).ToString();
//string转byte[]
System.Text.UnicodeEncoding converter = newSystem.Text.UnicodeEncoding();[csharp] view plaincopyprint?byte[] stringBytes = converter.GetBytes(inputString);
byte[] stringBytes = converter.GetBytes(inputString); [csharp] view plaincopyprint?//byte[]转string
//byte[]转string[csharp] view plaincopyprint?System.Text.UnicodeEncoding converter = newSystem.Text.UnicodeEncoding();
System.Text.UnicodeEncoding converter = newSystem.Text.UnicodeEncoding();[csharp] view plaincopyprint?stringoutputString = converter.GetString(stringByte);
stringoutputString = converter.GetString(stringByte);
[csharp] view plaincopyprint?
1.由string的rgb数值"255,255,0"转换为color
{
string[] color_params = e.Parameter.ToString().Split(',');
byte color_R = Convert.ToByte(color_params[0]);
byte color_G = Convert.ToByte(color_params[1]);
byte color_B = Convert.ToByte(color_params[2]);
}
2.由颜色名称字符串("black") 转化为color
{
//ColorConverter c = new ColorConverter();
//object obj = c.ConvertFrom();
//Color color = (Color)obj;
Color color = Color.FromRgb(color_R, color_G, color_B);
}
3.将blend的 8位颜色值转为color
/// <summary>
/// 将blend的8位颜色值转为color
/// </summary>
/// <param name="colorName"></param>
/// <returns></returns>
public Color ToColor(string colorName)
{
if (colorName.StartsWith("#"))
colorName = colorName.Replace("#", string.Empty);
int v = int.Parse(colorName, System.Globalization.NumberStyles.HexNumber);
return new Color()
{
A = Convert.ToByte((v >> 24) & 255),
R = Convert.ToByte((v >> 16) & 255),
G = Convert.ToByte((v >> 8) & 255),
B = Convert.ToByte((v >> 0) & 255)
};
}
-
- Brush br = new SolidColorBrush(Color.FromRgb(0,0,0));
-
- (Color)ColorConverter.ConvertFromString((string)str);
//color转为brush:
Brush br = new SolidColorBrush(Color.FromRgb(0,0,0));
//string转Color
(Color)ColorConverter.ConvertFromString((string)str);
-
- string和Brush的转换
- Brush color = newSolidColorBrush((Color)ColorConverter.ConvertFromString((string)str));
//Color转string((Color)value).ToString();
string和Brush的转换
Brush color = newSolidColorBrush((Color)ColorConverter.ConvertFromString((string)str));
//Brush转string
- ((Brush)value).ToString();
-
- System.Text.UnicodeEncoding converter = newSystem.Text.UnicodeEncoding();
((Brush)value).ToString();
//string转byte[]
System.Text.UnicodeEncoding converter = newSystem.Text.UnicodeEncoding();
- byte[] stringBytes = converter.GetBytes(inputString);
byte[] stringBytes = converter.GetBytes(inputString);
//byte[]转string
- System.Text.UnicodeEncoding converter = newSystem.Text.UnicodeEncoding();
System.Text.UnicodeEncoding converter = newSystem.Text.UnicodeEncoding();
- stringoutputString = converter.GetString(stringByte);
stringoutputString = converter.GetString(stringByte);
-
- 1.由string的rgb数值"255,255,0"转换为color
-
- {
- string[] color_params = e.Parameter.ToString().Split(',');
- byte color_R = Convert.ToByte(color_params[0]);
- byte color_G = Convert.ToByte(color_params[1]);
- byte color_B = Convert.ToByte(color_params[2]);
- }
-
- 2.由颜色名称字符串("black") 转化为color
-
- {
-
-
-
-
- Color color = Color.FromRgb(color_R, color_G, color_B);
-
- }
-
- 3.将blend的 8位颜色值转为color
-
-
-
-
-
-
-
- public Color ToColor(string colorName)
- {
- if (colorName.StartsWith("#"))
- colorName = colorName.Replace("#", string.Empty);
- int v = int.Parse(colorName, System.Globalization.NumberStyles.HexNumber);
- return new Color()
- {
- A = Convert.ToByte((v >> 24) & 255),
- R = Convert.ToByte((v >> 16) & 255),
- G = Convert.ToByte((v >> 8) & 255),
- B = Convert.ToByte((v >> 0) & 255)
- };
- }