RenderTargetBitmap is always anti-aliasing my DrawingVisual
Asked Answered
P

0

6

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);
Proscenium answered 2/1, 2014 at 0:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.