【发布时间】:2012-02-03 05:12:31
【问题描述】:
我想知道,是否有任何算法可以通过背景颜色确定最佳字体颜色以提高可读性。
例如: 我创建了一个带有动态文本和颜色的图标。如果颜色有点暗,我希望它设置字体颜色为白色,如果它相当亮,我希望它是黑色(甚至可能是灰色)。
public DynamicIcon( String iconText, Color backgroundColor )
{
this.iconText = iconText;
this.backgroundColor = backgroundColor;
this.fontColor = determineFontColor( backgroundColor );
}
//This is what I need (Pseudocode):
private fontColor determineFontColor( Color backgroundColor )
{
if( backgroundColor == bright )
return Color.BLACK;
if( backgroundColor == dark )
return Color.WHITE;
//If possible:
if( backgroundColor == somethingInBetween )
return Color.GRAYISH;
}
不幸的是,我没有找到任何类似的算法,尽管我有点确定它已经存在。有人有什么想法吗?
谢谢, 梅内
【问题讨论】: