Working with RGB and contrast-issues

moster67

Expert
Licensed User
Longtime User
I don't even know if I am using the right term calling it a contrast-problem so let me explain better.....

I have an activity with a fixed black background-colour. On the activity I have placed a label where the text-colour changes randomly every second. What happens is that sometimes (inevitably) the text-color generated is black, just like the activity-colour, or is a similar colour-shade which makes it impossible to read the text in the label.

So, I am wondering if there is some kind of formula which can be used to avoid this kind of contrast-issue between the two colours and which makes the text illegible or nearly. If yes and if there is a risk that the colours are very similar, what counter-measure can I choose to make sure that the text-color of the label will be readable. I guess I need to change one (or more) of the RGB-integers but again in what way?

Example-project is attached. Might not be easy to reproduce since this contrast-issue does not happens all the time but I guess it will eventually.
 

Attachments

  • testRGBContrast.zip
    6.3 KB · Views: 211

stevel05

Expert
Licensed User
Longtime User
Do you need so many possible colours? If you create a list (of as many as you need 20, 30, 40?) and select at random from there. you would have more control over what was produced.
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
I know, I could easily resolve it by creating a list of predefined colours (which are readable on a black background) as suggested by you.

But my question was more out of curiosity. If there is a formula which can be used or not? I could make the example even more difficult if I also generated the activity-colour randomly like:

B4X:
Activity.Color=Colors.RGB(Rnd(0,256),Rnd(0,256),Rnd(0,256))

I have seen apps used to check colour blindness (anomaloscope) and I guess they must be using some kind of formula.

Do you need so many possible colours? If you create a list (of as many as you need 20, 30, 40?) and select at random from there. you would have more control over what was produced.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
OK, then take a look at this link which discusses the issue. I am sure there will be many more discussions on the net elsewhere that are more complete.

If you you want to try that as a starting point android.graphics.Color object has static methods that can be called via reflection to convert HSV to RGB.

Hope this helps
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
Thanks for the links. I will see if I can understand the RGB colour model a bit more and the impact of saturation and so on.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
It maybe easier to deal with in Luma-Chroma color model. Luma signifies the intensity while chroma signifies the color. If luma is too low you will see nothing. If chroma is too close to the background chroma it will bw hard to distinguish the text.

Sent from my GT-I9000 using Tapatalk
 
Upvote 0
Top