Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Draw text on a .net Control with negative color of the background - blend

I'd like to draw a progress bar with percentage in its center, but I'd like the text to have negative (contrasted) color of the background.

So the part of the text that is over the filled portion of ProgressBar would be white and the part over unfilled portion would be white.

I could do this simply by "cheating"

  • painting the black part of the text first
  • painting the progress rectangle (it would cover the part to be hidden)
  • painting the white text over the progress rectangle only (clipping it)

The performance impact of painting the text twice is negligible in this application, but I'm interested if there is some simple way to do it in two steps only (like having the progress bar somehow invert the already painted text) with blending.

like image 919
Axarydax Avatar asked Oct 15 '22 07:10

Axarydax


1 Answers

What you're doing is fine. Old tricks like SetROP2() don't work anymore with text getting anti-aliased, especially with ClearType rendering. Getting the aliasing pixels with the wrong color is very noticeable. Graphics.CompositingMode accordingly doesn't support the effects anymore.

like image 64
Hans Passant Avatar answered Oct 20 '22 16:10

Hans Passant