开发者

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开发者_StackOverflow) with blending.


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.


You can use XOR to calculate the negative (inverted) color;

Public Function InvertColor(color As Long) As Long
    Return (color Xor &HFFFFFF)
End Function
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜