We should have done something similar in our system: based on the background, we color the black or white font. The solution we found is not perfect and in some rare cases chooses the wrong color, but we are very happy with it.
Here's what we did:
int red = 0; int green = 0; int blue = 0; if ( backgroundColor.red + backgroundColor.green + backgroundColor.blue < 383 ) { red = 255; green = 255; blue = 255; }
And then we use the values red , green and blue to create a new Color object.
The magic number 383 is the result of (255 + 255 + 255) / 2
source share