How to convert Hex to RGB?

后端 未结 8 1706
暖寄归人
暖寄归人 2021-02-12 11:13

I am trying to use this to figure out if a color is light or dark

Evaluate whether a HEX value is dark or light

Now. It takes in a int



        
8条回答
  •  我在风中等你
    2021-02-12 12:04

    You can use:

    public string GenerateRgba(string backgroundColor, decimal backgroundOpacity)
    {
     Color color = ColorTranslator.FromHtml(hexBackgroundColor);
     int r = Convert.ToInt16(color.R);
     int g = Convert.ToInt16(color.G);
     int b = Convert.ToInt16(color.B);
     return string.Format("rgba({0}, {1}, {2}, {3});", r, g, b, backgroundOpacity);
    }
    

    Link To original Post by jeremy clifton on git

提交回复
热议问题