c#-WPF中的模糊转换文本

我正在使用DrawingContext.DrawText和DrawingContext.PushTransfrom在WPF中的Visual Layer上创建旋转的文本,但是正如您在下图中看到的那样,旋转的文本在图像的某些区域相当模糊.

有什么我可以用来改善的选择吗?文本使用Arial字体.

public class BeamTextDrawing : FrameworkElement
{
    private readonly VisualCollection _visuals;
    public BeamTextDrawing(double scale)
    {
        if (scale <= 0)
        {
            scale = 1;
        }
        var typeface = Settings.BeamTextTypeface;
        var cultureinfo = Settings.CultureInfo;
        var flowdirection = Settings.FlowDirection;
        var textsize = Settings.BeamTextSize / scale;
        var beamtextcolor = Settings.InPlanBeamTextColor;

        _visuals = new VisualCollection(this);

        foreach (var beam in Building.BeamsInTheElevation)
        {
            var drawingVisual = new DrawingVisual();
            using (var dc = drawingVisual.RenderOpen())
            {
                var text = Convert.ToString(beam.Section.Id);
                //text = scale.ToString();
                var ft = new FormattedText(text, cultureinfo, flowdirection,
                                            typeface, textsize, beamtextcolor)
                {
                    TextAlignment = TextAlignment.Center
                };

                var x1 = beam.ConnectivityLine.I.X;
                var y1 = beam.ConnectivityLine.I.Y;
                var x2 = beam.ConnectivityLine.J.X;
                var y2 = beam.ConnectivityLine.J.Y;

                var v1 = new Point(x2, y2) - new Point(x1, y1);
                var v2 = new Vector(1, 0);

                var hwidth = textsize;
                var l = Geometrics.GetOffset(x1, y1, x2, y2, hwidth + 5/scale);

                var angle = Vector.AngleBetween(v1, v2);
                var x = 0.5 * (l.X1 + l.X2);
                var y = 0.5 * (l.Y1 + l.Y2);

                var r = new RotateTransform(angle, x, SelectableModel.FlipYAxis(y));
                dc.PushTransform(r);
                dc.DrawText(ft, SelectableModel.FlipYAxis(x, y));
            }
            _visuals.Add(drawingVisual);
        }
    }

    protected override Visual GetVisualChild(int index)
    {
        return _visuals[index];
    }

    protected override int VisualChildrenCount
    {
        get
        {
            return _visuals.Count;
        }
    }
}

更新:

这是使用此代码后的图像:

TextOptions.SetTextFormattingMode(this, TextFormattingMode.Display);

我仍然得到模糊的结果.查看图像下部的中间光束文本.

解决方法:

您可以更改TextFormattingMode以防止文本模糊:

public BeamTextDrawing(double scale)
{
    TextOptions.SetTextFormattingMode(this, TextFormattingMode.Display);
    // .. Your other code
上一篇:WPF程序使用矢量图资源绘制井口装置图


下一篇:Vue-Router query 命名路由 params props