2

I'm working on a program using C# and WPF and I was curious about getting the text color of some text I have to change dynamically based on what the background image I set is.

The background images are loaded by random (I will have no control over what they are) and I need to maintain readability of the fonts depending on what it is.

As you can see here: http://i.gyazo.com/820c45dde9d767dcd7ab2a92bd1de898.png

With this background image set, there's no way to read what the text has to say. Meanwhile, it would look fine on a lighter background.

Basically what I think needs to happen is

  1. Get the most used color in that image
  2. Find out if it's a "light or dark color"
  3. Change the text accordingly How could I do this? Whether it's programmatically or in the WPF XAML (i'm still new to using WPF so bear with me there).

Thanks in advanced,

Mike

2
  • 3
    you can use converters to 'set properties after processing some data'. take a look at wpftutorial.net/ValueConverters.html. If you can bind to the image and use converter, you can set the foreground of the Text element. Commented Jun 4, 2014 at 22:10
  • 3
    There's still a good chance your text wont be readable. If the most used color is black and you decide to use white, there's still a chance that the text will sit over some white area of the background. Black text with a white outline can be read over anything though. Commented Jun 4, 2014 at 22:28

1 Answer 1

1

I would agree that trying to select a text colour dynamically isn't ideal. Even if you select a colour that makes some of the text visible there is no guarantee it won't pass through a portion of your images which hides it.

Personally I would use a label with a white background but reduce the background opacity to show some part of the image behind. That way your text will always sit on a lightened area and dark text will always work.

Andy.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.