让foregroundcolor黑色或白色取决于背景 [英] Make foregroundcolor black or white depending on background

查看:476
本文介绍了让foregroundcolor黑色或白色取决于背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜欢的东西计算RGB分量的平均值,然后决定是否使用黑色或白色的?

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

我必须RGB转换为HSV在第一步,因为RGB并不总是如人的眼睛看到了什么?

Do I have to convert RGB to HSV in first step 'cause RGB is not always what the human eyes see?

我使用C#

推荐答案

怎么样?

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

这篇关于让foregroundcolor黑色或白色取决于背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆