我必须将 TextBox 中的文本呈现为 WriteableBitmap。此代码运行良好,但其中的文本模糊或抗锯齿。关于如何保持别名和清晰的任何想法?
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);
我发现没有用:
TextOptions.SetTextFormattingMode(dv, TextFormattingMode.Display);
TextOptions.SetTextRenderingMode(dv, TextRenderingMode.Aliased);
或者
RenderOptions.SetBitmapScalingMode(dv, BitmapScalingMode.NearestNeighbor);
RenderOptions.SetEdgeMode(dv, EdgeMode.Aliased);