如果背景颜色已知,如何找到好看的字体颜色? [英] How to find good looking font color if background color is known?

查看:36
本文介绍了如果背景颜色已知,如何找到好看的字体颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎有很多色轮、颜色选择器和颜色匹配器 Web 应用程序,您提供一种颜色,他们会找到其他几种颜色,组合使用时会创建和谐的布局.然而,它们中的大多数只关注背景颜色,并且在每种背景颜色上打印的任何文本(如果在预览中打印了文本)要么是黑色的,要么是白色的.

There seem to be so many color wheel, color picker, and color matcher web apps out there, where you give one color and the they'll find a couple of other colors that will create a harmonic layout when being used in combination. However most of them focus on background colors only and any text printed on each background color (if text is printed at all in the preview) is either black or white.

我的问题是不同的.我知道我想用于文本区域的背景颜色.我需要帮助的是选择几种颜色(越多越好)我可以用作此背景上的字体颜色.最重要的是颜色将确保字体可读(对比度不能太低,也不能太高以避免眼睛受到压力),当然前景和背景的组合看起来不错.

My problem is different. I know the background color I want to use for a text area. What I need help with is choosing a couple of colors (the more, the merrier) I can use as font colors on this background. Most important is that the color will make sure the font is readable (contrast not being too low, also maybe not being too high to avoid that eyes are stressed) and of course that the combination of foreground and background just looks good.

有人知道这样的应用程序吗?我更喜欢网络应用程序而不是我必须下载的任何东西.谢谢.

Anyone being aware of such an application? I'd prefer a web application to anything I have to download. Thanks.

推荐答案

如果您需要算法,请尝试以下操作:将颜色从 RGB 空间转换为 HSV 空间(色相、饱和度、值).如果您的 UI 框架无法做到,请查看这篇文章:http://en.wikipedia.org/wiki/HSL_and_HSV#Conversion_from_RGB_to_HSL_or_HSV

If you need an algorithm, try this: Convert the color from RGB space to HSV space (Hue, Saturation, Value). If your UI framework can't do it, check this article: http://en.wikipedia.org/wiki/HSL_and_HSV#Conversion_from_RGB_to_HSL_or_HSV

色调在 [0,360) 中.要找到相反"颜色(想想色轮),只需添加 180 度:

Hue is in [0,360). To find the "opposite" color (think colorwheel), just add 180 degrees:

h = (h + 180) % 360;

对于饱和度和值,反转它们:

For saturation and value, invert them:

l = 1.0 - l;
v = 1.0 - v;

转换回 RGB.即使大多数组合看起来很难看,这也应该始终为您提供高对比度.

Convert back to RGB. This should always give you a high contrast even though most combinations will look ugly.

如果你想避免丑"的部分,就用几个好"的组合来建一张表,找出差异最小的那个

If you want to avoid the "ugly" part, build a table with several "good" combinations, find the one with the least difference

def q(x):
    return x*x
def diff(col1, col2):
    return math.sqrt(q(col1.r-col2.r) + q(col1.g-col2.g) + q(col1.b-col2.b))

并使用它.

这篇关于如果背景颜色已知,如何找到好看的字体颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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