根据背景将前景色设为黑色或白色 [英] Make foregroundcolor black or white depending on background

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

问题描述

类似于计算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;
}

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

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