智能色彩检测 [英] Intelligent Color Detection

查看:235
本文介绍了智能色彩检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发一种医疗调度系统,允许用户根据特定状态定义在日历上显示的颜色。我们的问题是,如果用户选择深色背景颜色,我们使用深色字体,字体不显示。同样,如果他们选择浅色,我们使用轻的字体。出于各种原因,我们不想让用户设置两种颜色。

We are working on a medical scheduling system that allows users to define colors to show on the calendar based on a certain status. The issue we have is that if the user picks a dark background color and we are using a dark font, the font doesn't show. Likewise if they pick a light color and we are using a light font. For a variety of reasons, we don't want to have the user setting both colors.

但是,我们想知道是否有一个特定的模式的十六进制代码的颜色。也许如果它小于一个给定的值,应该使用黑色字体和浅色字体使用否则?

But, we wonder if there is a particular pattern to the hex codes of colors. Perhaps if it is less than a given value, a dark font should be used and a light font used otherwise?

那么,有没有一种智能的方法来根据用户选择的背景颜色来编程选择字体颜色?

So, is there an intelligent way to programatically pick the font color based on the user's choice of background color?

Amy

推荐答案

您可以使用十六进制代码以数学方式计算两种颜色之间的对比度。有了这些信息,问题只是文本(白色或黑色)与选择的背景颜色有更多的对比度。此网站显示如何使用PHP或Javascript编写该代码,但可轻松适应其他语言。

You can use the hex codes to mathematically calculate the contrast between two colors. With that information the question is just which color of text (white or black) has more contrast with the chosen background color. This site shows how to write that code in PHP or Javascript, but it could easily be adapted to other languages.

http://24ways.org/2010/calculating-color-contrast

这篇关于智能色彩检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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