Search code examples
c#stringsystem.drawing

Drawing a contrasted string on an image


So, I have a snapshot of a video source, which I get into an Image, grab a Graphics object for it, and then draw a timestamp in the bottom right of the image. No problem thus far. However, I cannot guarantee what colour is going to be behind the text, so no matter what brush I use, it will almost certainly clash with some of the images that it is drawn on, making the text unreadable.

I am wondering if anyone knows of a way (either a method in .net, or a nice algorithm), for determining the best colour for a string based on the image behind it.

Cheers


Solution

  •  just draw the string 5 times.
     One time 1(or2) pixels to the left in black
     One time 1(or2) pixels to the right in black
     One time 1(or2) pixels above it in black
     One time 1(or2) pixels below it in black
     and the final time in white on the place where you want it