String、Brush、Color 相互转换

1、String转换成Color

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

2、String转换成Brush

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

3、Color转换成Brush

Brush brush = new SolidColorBrush(color));

4、Brush转换成Color有两种方法:

(1)先将Brush转成string,再转成Color。

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

(2)将Brush转成SolidColorBrush,再取Color。

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

String、Brush、Color 相互转换

时间: 2024-08-08 03:47:40

String、Brush、Color 相互转换的相关文章

c#-WPF string,color,brush之间的转换

原文:c#-WPF string,color,brush之间的转换 String转换成Color string-"ffffff" Color color = (Color)ColorConverter.ConvertFromString(string); String转换成Brush BrushConverter brushConverter = new BrushConverter(); Brush brush = (Brush)brushConverter.ConvertFromS

String与InputStream相互转换

1.String to InputStream String str = "String与InputStream相互转换"; InputStream   in_nocode   =   new   ByteArrayInputStream(str.getBytes());  InputStream   in_withcode   =   new   ByteArrayInputStream(str.getBytes("UTF-8")); 2.InputStream

string 到 Color 的转换示例:

string colorstr = "#FF4D4D4D";string hex = colorstr.ToString().Replace("#", "");byte alpha;byte pos = 0;if (hex.Length == 8){ alpha = System.Convert.ToByte(hex.Substring(pos, 2), 16); pos = 2;}else{ alpha = System.Convert.ToB

C#中String 与Color之间的相互转换

其实,我们平常如果要在数据库存放Color类型值的话,肯定会在数据库中建立varchar类型.对吧.但是Color怎么存才合适呢,当然是要转为String了.这里小宋作个简介吧.其实用法很简单:      这个控件中,最后取得的当然是Color类型的值了.所在转为String只要用转换器就行.   String  color = System.Drawing.ColorTranslator.ToHtml(colorEdit1.Color); //将Color对象转为String对象.如#AABB

用#FFFF2222的string生成color

private 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.ToBy

C++ string和int相互转换

首先需要C++ 11的支持 打开devC++,点击tools,点击编译环境,然后出现的框第一个勾选,输入-std=c++11即可 然后使用 to_string() 和 atoi() 就可以轻松实现其相互转换 1 #include <iostream> 2 #include <algorithm> 3 #include <string> 4 #include <sstream> 5 typedef long long ll; 6 using namespace

2015.5.11 string与byte[]相互转换

string类型转成byte[]: byte[] byteArray = System.Text.Encoding.Default.GetBytes ( str ); 反过来,byte[]转成string: string str = System.Text.Encoding.Default.GetString ( byteArray );

JAVA中int、String的类型相互转换

int -> String int i=12345;String s="";第一种方法:s=i+"";第二种方法:s=String.valueOf(i);这两种方法有什么区别呢?作用是不是一样的呢?是不是在任何下都能互换呢? String -> int s="12345";int i;第一种方法:i=Integer.parseInt(s);第二种方法:i=Integer.valueOf(s).intValue();这两种方法有什么区别

java中String\十六进制String\byte[]之间相互转换函数

java二进制,字节数组,字符,十六进制,BCD编码转换2007-06-07 00:17/** *//** * 把16进制字符串转换成字节数组 * @param hex * @return */ public static byte[] hexStringToByte(String hex) { int len = (hex.length() / 2); byte[] result = new byte[len]; char[] achar = hex.toCharArray(); for (i