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

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

问题描述

似乎有这么多的色轮,颜色选择器和颜色匹配器网络应用程序,在那里你给一种颜色,他们会找到一些其他颜色,将创建一个谐波布局,当组合使用。但是大多数人只关注背景颜色,并且每种背景颜色上打印的任何文字(如果在预览中全部打印文本)是黑色或白色。



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

任何人都知道这样的应用程序?我更喜欢一个Web应用程序到我必须下载的任何东西。谢谢。

解决方案

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



色相位于[0,360]。要找到相反的颜色(认为颜色轮),只需添加180度:

  h =(h + 180)%360 ; 

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

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

转换回RGB。这应该总是给你一个很大的对比度,即使大多数组合看起来很丑陋。



如果你想避免丑部分,建立一个表与几个好组合,找到最小差异的一个

  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) )

并使用它。


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.

解决方案

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

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;

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))

and use that.

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

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