码迷,mamicode.com
首页 > 其他好文 > 详细

颜色转换

时间:2014-07-21 13:33:27      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:style   color   os   io   art   re   

Color --->string(十六进制)

        public string GetHexByArgb(Color color)
        {
            string rtn = string.Empty;

            Color tmpColor = Color.FromArgb(color.A, color.R, color.G, color.B);

            rtn = "#" + Convert.ToString(tmpColor.ToArgb(), 16);

            rtn = rtn.PadRight(9, '0');

            return rtn;
        }


string ---> Color

        public Color GetColor(string strArgb)
        {
            int argb;
            Color color = Color.Empty;

            if (string.IsNullOrEmpty(strArgb) == false)
            {
                if (int.TryParse(strArgb.Remove(0, 1), NumberStyles.HexNumber, null, out argb) == true)
                {
                    color = Color.FromArgb(argb);
                }
            }

            return color;
        }


Silverlight中颜色转换

        public SolidColorBrush ConvertColor(string color)
        {
            if (!string.IsNullOrEmpty(color) && color.Contains("#"))
            {
                if (color.StartsWith("#"))
                {
                    color = color.Replace("#", string.Empty);
                }
                int v = int.Parse(color, System.Globalization.NumberStyles.HexNumber);
                return new SolidColorBrush(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)
                });
            }
            return null;
        }


 

 

颜色转换,布布扣,bubuko.com

颜色转换

标签:style   color   os   io   art   re   

原文地址:http://blog.csdn.net/jasminedawn/article/details/38013559

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!