gpt4 book ai didi

wpf - 将 TextOptions.TextFormattingMode 与 FormattedText 结合使用

转载 作者:行者123 更新时间:2023-12-02 11:57:42 26 4
gpt4 key购买 nike

使用 WPF4,您可以通过将 TextOptions.TextFormattingMode="Display"和 TextOptions.TextRenderingMode="Aliased"添加到 xaml 来获得非模糊文本:

<Window
TextOptions.TextFormattingMode="Display"
TextOptions.TextRenderingMode="Aliased">

这对我来说效果很好,除了当我使用 DrawingContext.DrawText 绘制文本时,如下所示:

void DrawText(DrawingContext dc)
{
FormattedText ft = new FormattedText("Hello World",
System.Globalization.CultureInfo.CurrentCulture,
System.Windows.FlowDirection.LeftToRight,
new Typeface(FontFamily, FontStyle, FontWeight, FontStretch),
FontSize,
brush);
dc.DrawText(ft, new Point(rect.Left, rect.Top));
}

如何使用 FormattedText 绘制非模糊文本?即我希望使用 TextOptions.TextFormattingMode="Display"和 TextOptions.TextRenderingMode="Aliased"。

最佳答案

FormattedText 有一个重载的构造函数,允许指定 TextFormattingMode:http://msdn.microsoft.com/en-us/library/ee474866.aspx

void DrawText(DrawingContext dc)
{
FormattedText ft = new FormattedText("Hello World",
System.Globalization.CultureInfo.CurrentCulture,
System.Windows.FlowDirection.LeftToRight,
new Typeface(FontFamily, FontStyle, FontWeight, FontStretch),
FontSize,
brush,
null,
TextFormattingMode.Display);
dc.DrawText(ft, new Point(rect.Left, rect.Top));
}

关于wpf - 将 TextOptions.TextFormattingMode 与 FormattedText 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2550632/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com