algorithm - Determine font color based on background color -
Given a system (for example a website) that optimizes the background color for a user for some section , But there is no font color (to keep the number of choices at least), is there a way to programmatically determine whether a "light" or "dark" font color is necessary?
I'm sure there are some algorithms, but I am not sure enough about color, shine, etc. to understand it on my own, to understand it on my own.
I had to face the same trouble. I should get a good method to select opposite font colors to display text labels on color kells / heatmaps. It should be a universal method and the resulting color was to be "good looking", which means that the simpler complementary color was not a good solution - sometimes it generates a weird, very intense color that was hard to see and read.
After long hours of trying to solve this problem and trying, I came to know that the best solution is to select white font for "black" colors, and for the "bright" colors There is a black font.
Example of function C #:
Color contrast color (color color) {int d = 0; // Count of perceptional luminance - Human eyes are in favor of green color ... double A = 1 - (0.299 * color. R + 0.587 * color .g + 0.114 * color .b) / 255; If (a & lt; 0.5) d = 0; // bright color - black font other D = 255; // Dark Color - Return the white font color. FOMARBBB (D, D, D); }
It was tested for many different colors (rainbow, grayscale, summer, ice, and many others) and this is the only "universal" method I have found.
edit
changed the formula for counting "deceptive shine" to count a
- it looks really better!
Edit 2 @WebSeed has provided a brilliant example of this algorithm:
Comments
Post a Comment