1
votes

I have a difficulty as I am trying to render a character with a specific font style to the bitmap image (black and white). My question is the font is basically black and white and I am writing the character in black (against white background), however when I convert it to bitmap image I get a coloured thin outline around the bindery of my character.

Can anyone tell me where that grey color comes from while I am writing it with black color and how can i get ONLY black and white pixels?

1
Probably anti-aliasing: en.wikipedia.org/wiki/Spatial_anti-aliasing - it will look pretty crappy without it.Tom McClure
i have actually used that, doesn't work. my question is where does the grey color comes from in bitmap conversion. i was expecting to get pure black and white image!CowBoy
@user3266873 see the TextRenderingHint property of graphics you use. Change it...L.B

1 Answers

1
votes

The pixels that aren't completely black or completely white are the result of anti-aliasing. Anti-aliasing is used by default since everyone who doesn't know about it probably wants it.

I suggest two alternatives. One, create your bitmap with a one bit per pixel format, which will not give anti-aliasing a chance. Second, you can go through the resulting image after the text has been drawn pixel by pixel and adjust each pixel to either black or white based on a threshold. I.e. if the picture is darker than half then it's black, otherwise it's white. e.g. if (red+green+blue > 383) set_pixel_white() else set_pixel_black(); But you'll need be ready for some rather funny results. You may need to play with the thresholds.

PS there's a better solution, you can tweak anti-aliasing. MSDN You'll set your rendering to System.Drawing.Text.TextRenderingHint.SingleBitPerPixel or something that suits you.