如何以编程方式选择良好的对比度RGB颜色? [英] How to pick good contrast RGB colors programmatically?
问题描述
假设您的程式:
-
color A
我们随机选择的颜色
知道颜色A
,如何选择< c $ c> color A ?
Knowing color A
, how can I pick a color B
that will be in high contrast with color A
?
这个问题可以进一步简化为:想象两个相邻的方块,应该 / strong>颜色不一样
The problem can be further reduced to: "imagine 2 squares filled with color next to one another. It should be unambiguously clear to a human eye that colors are not the same"
示例:
- Black - >白色
- 蓝色 - >白色
推荐答案
Web内容无障碍指南(WCAG)2.0(http://www.w3.org/TR/2008/REC-WCAG20-20081211)中提供了一些信息
There is some information in the Web Content Accessibility Guidelines (WCAG) 2.0 (http://www.w3.org/TR/2008/REC-WCAG20-20081211)
对比度: http://www.w3.org/TR/2008/REC -WCAG20-20081211 /#contrast-ratiodef
相对亮度:http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
有一个很好的例子,在这个网站,但
There's a good example in this site but he calculate where two colors are enough, not how to get them.
要选择具有良好对比度的颜色,我会选择互补的颜色:例如,选择
To choose a color with good contrast, I'd go with complementary colors: for example, choose the random color A, transform it to a HSV space, get the complementary hue.
互补色调:在将颜色从RGB转换为HSV之后,互补色调将是180度附加(或0.5,在0-1归一化色调值中)。 此网站在PHP中有一些相关信息
Complementary hue: after you transform color from RGB to HSV, complementary hue will be 180 degrees appart (or 0.5, in a 0-1 normalized hue value). This site has something about it in PHP
这篇关于如何以编程方式选择良好的对比度RGB颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!