Converting a string HEX to color in Windows Phone Runtime c#

前端 未结 8 1698
执念已碎
执念已碎 2021-02-09 07:30

I am working on a windows phone game, and I got stuck when I wanted to convert a HEX string into Color. On windows phone 8 silverlight it is not a problem but I cannot find a so

8条回答
  •  故里飘歌
    2021-02-09 07:55

    I made a method from the top answer here:

    private Windows.UI.Color GetColorFromHex(string hexString)
    {
        hexString = hexString.Replace("#", string.Empty);
        byte r = byte.Parse(hexString.Substring(0, 2), NumberStyles.HexNumber);
        byte g = byte.Parse(hexString.Substring(2, 2), NumberStyles.HexNumber);
        byte b = byte.Parse(hexString.Substring(4, 2), NumberStyles.HexNumber);
    
        return Windows.UI.Color.FromArgb(byte.Parse("1"), r, g, b);
    }
    

提交回复
热议问题