RenderTargetBitmap is always anti-aliasing my DrawingVisual

672 views Asked by At

I have to render the text from a TextBox into a WriteableBitmap. This code is working pretty well but the text in it is blurry or anti-aliased. Any ideas on how to keep it aliased and crisp?

text = new FormattedText(tb.Text,
            new CultureInfo("de-de"),
            FlowDirection.LeftToRight,
            new Typeface(tb.FontFamily, FontStyles.Normal, tb.FontWeight, new FontStretch()),
            tb.FontSize,
            tb.Foreground);


            drawingContext = dv.RenderOpen();
            drawingContext.DrawText(text, Pos);
            drawingContext.Close();


            rtb.Render(dv);
            rtb.CopyPixels(new Int32Rect(0, 0, rtb.PixelWidth, rtb.PixelHeight), wb.BackBuffer, wb.BackBufferStride * wb.PixelHeight, wb.BackBufferStride);

What I found did not work:

TextOptions.SetTextFormattingMode(dv, TextFormattingMode.Display);
TextOptions.SetTextRenderingMode(dv, TextRenderingMode.Aliased);

or

RenderOptions.SetBitmapScalingMode(dv, BitmapScalingMode.NearestNeighbor);
RenderOptions.SetEdgeMode(dv, EdgeMode.Aliased);
0

There are 0 answers