I rendering text to bitmap using WPF. I would like to turn off anti-aliasing, I mean I want the pixels be white or black. But the text is still blured, some pixels are even grey.
Here is my code. Some lines are probably not needed.
RenderTargetBitmap bm = new RenderTargetBitmap(bitmapWidth, bitmapHeight, dpiX, dpiY, PixelFormats.Pbgra32);
DrawingVisual drawing_visual = new DrawingVisual();
RenderOptions.SetEdgeMode(drawing_visual, EdgeMode.Unspecified);
RenderOptions.SetBitmapScalingMode(drawing_visual, BitmapScalingMode.Linear);
RenderOptions.SetEdgeMode(bm, EdgeMode.Unspecified);
RenderOptions.SetBitmapScalingMode(bm, BitmapScalingMode.Linear);
DrawingContext drawing_context = drawing_visual.RenderOpen();
FormattedText ft = new FormattedText("my text", CultureInfo.InvariantCulture, System.Windows.FlowDirection.LeftToRight, typeface, fontSize, Brushes.Black);
drawing_context.DrawText(ft, new Point(0, 0));
drawing_context.Close();
bm.Render(drawing_visual);
Rendered image:
To check the solution, you can download source code from GitHub:
https://github.com/qub1n/Font-rendering.git
EdgeMode
toAliased
? – l33t