Transparent antialias text problem
-
I want to add text to a transparent bitmap (in C# 2.0). The text can be black, white, or red. But it seems that when I use the DrawString method of the Graphics object it antialias the text with black. This works okay when I have white or red text and the transparent bitmap is shown over a mainly black background, but looks crap when I have black or red text and the transparent bitmap is shown over a mainly white background. (White text looks blurred, red text has black bits round edges.) Does anyone know how to antialias to white on a transparent graphic? Or antialias to transparent properly? (I have tried setting the bitmap to white first. Then after the text has been added, floodfilling back to transparent. Sort of works except all the closed loops in letters like o, d, b, p ... etc.)
-
I want to add text to a transparent bitmap (in C# 2.0). The text can be black, white, or red. But it seems that when I use the DrawString method of the Graphics object it antialias the text with black. This works okay when I have white or red text and the transparent bitmap is shown over a mainly black background, but looks crap when I have black or red text and the transparent bitmap is shown over a mainly white background. (White text looks blurred, red text has black bits round edges.) Does anyone know how to antialias to white on a transparent graphic? Or antialias to transparent properly? (I have tried setting the bitmap to white first. Then after the text has been added, floodfilling back to transparent. Sort of works except all the closed loops in letters like o, d, b, p ... etc.)
I found this[^], which seems to have some work arounds, from a quick google on c# antialias problems The link above is from fairly near the top of a loooooong list.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”
-
I want to add text to a transparent bitmap (in C# 2.0). The text can be black, white, or red. But it seems that when I use the DrawString method of the Graphics object it antialias the text with black. This works okay when I have white or red text and the transparent bitmap is shown over a mainly black background, but looks crap when I have black or red text and the transparent bitmap is shown over a mainly white background. (White text looks blurred, red text has black bits round edges.) Does anyone know how to antialias to white on a transparent graphic? Or antialias to transparent properly? (I have tried setting the bitmap to white first. Then after the text has been added, floodfilling back to transparent. Sort of works except all the closed loops in letters like o, d, b, p ... etc.)
I don't think it's possible to generate a semi-transparent bitmap with a single alpha value per pixel which will properly render ClearType text against arbitrarily-colored backgrounds (when drawing yellow text on a black background, a particular pixel may have to be red, but when drawing on a white background it may have to be yellow). If one refrains from ClearType-style use of colors for sub-pixel addressing, one could generate a bitmap that would depict a nicely anti-aliased font when overlaid on any background, by setting the color of any area of the bitmap which touched the letters to the font color, and varying the alpha to properly soften the edges. I don't think that's what Microsoft does, though. Still, you might want to experiment some with the property (I forget what it's called) that switches between drawing using an alpha value, or copying an alpha value to drawn pixels). It would be nice if there were a way of restricting drawing operations to either act only on the alpha channel, or leave the alpha channel alone while acting on color. I'm unaware of how to do those things, though.
-
I want to add text to a transparent bitmap (in C# 2.0). The text can be black, white, or red. But it seems that when I use the DrawString method of the Graphics object it antialias the text with black. This works okay when I have white or red text and the transparent bitmap is shown over a mainly black background, but looks crap when I have black or red text and the transparent bitmap is shown over a mainly white background. (White text looks blurred, red text has black bits round edges.) Does anyone know how to antialias to white on a transparent graphic? Or antialias to transparent properly? (I have tried setting the bitmap to white first. Then after the text has been added, floodfilling back to transparent. Sort of works except all the closed loops in letters like o, d, b, p ... etc.)
Okay. After playing around with a number of options without luck I decided to try a completely different approach. What I did was to create a second (temporary) bitmap with the same dimensions as the transparent target but with a white background. I then wrote on it in black. Finally I merged this into the transparent bitmap by examing each pixel in my second bitmap and setting the corresponding pixel in the target with RGB set to the target colour and the 'A' byte set to 255 - ((old R + old G + old B) / 3). Surprisingly, this worked and gives me true antialias to transparent. :-D If anyone's interested I've posted the code here [^]