Make foregroundcolor black or white depending on background

后端 未结 5 2049
不知归路
不知归路 2020-11-30 22:23

Something like calculating the average value of rgb components and then decide whether to use black or white?

Do I have to convert RGB to HSV in first step \'cause R

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 22:55

    what about that?

    private static Color GetReadableForeColor(Color c)
    {
        return (((c.R + c.B + c.G) / 3) > 128) ? Color.Black : Color.White;
    }
    

提交回复
热议问题