GDI + text has a black edge

I clear the image with a transparent color (120 alpha) and then draw a line with a gradient on it and then draw this image on a larger image, but the text has a blackish edge, instead of being beautiful and as it should be. The text looks great if the background is selected 255 alpha.

120 Alpha: Image

255 Alpha: Image

As you can see, the text is much easier to read with the background completely opaque.

Note: the green dot is my cursor

Edit: gfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;removes black edges, but blurred, I will try other combinations of graphics settings and see how this happens.

Edit: gfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;It looks much better, although font A in Arial looks a little funky

+3
source share
1 answer

This is normal behavior. You must change your drawing order so that everything is correct.

As you draw text on a translucent surface, its smoothing pixels will also be translucent, but between the color of the text and the background of the first image.

Now, if you draw the result on another image, you will have the same transparent pixels, where there is no text, there is no transparency, where the text and color variables and colors for the smoothing pixels.

Note that they will have different colors, as anti-aliasing tries to propagate color differences as well as differences in brightness.

Either write on an opaque surface, or hold the recording to the end. (Or turn off all anti-aliasing, but that's not nice.)

0
source

All Articles