Possible Duplicate:
given a background color, how to get a foreground color that make it readable on that background color?
I wonder, if there is any algorithm to determine the optimal fontcolor for readability by its background color.
For example: I create an icon with dynamic text and color. If the color is kinda dark, I want it to set the font color to white and if its fairly bright, I want it to be in black (or maybe even grayish).
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;
}
Unfortunatly I didnt find any algorithm like that, eventhough I am kinda sure, that it already exists. Anyone has any ideas?
thanks, ymene