用于给定背景颜色的良好文本前景颜色 [英] Good text foreground color for a given background color

查看:238
本文介绍了用于给定背景颜色的良好文本前景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在绘制颜色选择按钮,我正在寻找一个漂亮和简单的公式,以获得一个好的文本颜色(前景)为RGB中给定的背景颜色。

I'm drawing a color selection button and I'm looking for a nice and simple formula to get a good text color (foreground) for a given background color in RGB.

一个简单的尝试就是采取补色,但这将产生一个奇怪的按钮,像纯蓝色或纯红色。

有什么知名的这样做吗?

A simple try would be to just take the complement color but this will produce an odd looking button for colors like pure blue or pure red.
Is there something well known that does this?

如果有问题,我会使用QT。

If it matters at all, I'm using QT.

推荐答案

p>为了最大的清晰度,你需要最大的亮度对比度,而不会进入不能一起工作的色调。最一致的方法是使用黑色白色作为文字颜色。

For maximum legibility, you want maximum brightness contrast without getting into hues which don't work together. The most consistent way to do this is to stick with black or white for the text color. You might be able to come up with more aesthetically pleasing schemes, but none of them will be more legible.

要在黑色或白色之间选择,你需要知道亮度的背景。这有点复杂,由于两个因素:

To pick between black or white, you need to know the brightness of the background. This gets a little more complicated, due to two factors:


  • 个人基本红,绿,蓝的感知亮度不相同。我可以给出的最快的建议是使用传统公式将RGB转换为灰色 - R * 0.299 + G * 0.587 + B * 0.114。还有很多其他公式。

  • The perceived brightness of the individual primaries red, green, and blue are not identical. The quickest advice I can give is to use the traditional formula to convert RGB to gray - R*0.299 + G*0.587 + B*0.114. There are lots of other formulas.

应用于显示器的伽玛曲线使中间灰度值高于预期值。这很容易通过使用186作为中间值而不是128来解决。任何小于186应该使用白色文本,任何大于186应该使用黑色文本。

The gamma curve applied to displays makes the middle gray value higher than you'd expect. This is easily solved by using 186 as the middle value rather than 128. Anything less than 186 should use white text, anything greater than 186 should use black text.

这篇关于用于给定背景颜色的良好文本前景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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