当我使用画布缩放时,我需要“稳定”应用程序中的文本渲染。
我有以下代码:
<Window x:Class="WpfApplication4.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="356" Width="804">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ScrollViewer
PreviewMouseWheel="ScrollViewer_PreviewMouseWheel" Grid.Row="0">
<Canvas>
<Canvas.LayoutTransform>
<TransformGroup>
<ScaleTransform x:Name="scaleTransform"/>
</TransformGroup>
</Canvas.LayoutTransform>
<TextBlock Canvas.Left="34" Canvas.Top="47" Height="23" Name="textBlock1" Text="TK QSDFWPO Aàâéèêëîïôùûüÿçæœ; Ideal, Aliased" TextOptions.TextFormattingMode="Ideal" TextOptions.TextRenderingMode="Aliased" FontSize="11" FontFamily="Times New Roman" FontWeight="Bold" />
<TextBlock Canvas.Left="34" Canvas.Top="81" Height="23" Name="textBlock2" Text="TK QSDFWPO Aàâéèêëîïôùûüÿçæœ; Ideal, ClearType" TextOptions.TextFormattingMode="Ideal" TextOptions.TextRenderingMode="ClearType" FontSize="11" FontFamily="Times New Roman" FontWeight="Bold" />
<TextBlock Canvas.Left="35" Canvas.Top="115" Height="23" Name="textBlock3" Text="TK QSDFWPO Aàâéèêëîïôùûüÿçæœ; Ideal, Grayscale" TextOptions.TextFormattingMode="Ideal" TextOptions.TextRenderingMode="Grayscale" FontSize="11" FontFamily="Times New Roman" FontWeight="Bold" />
<TextBlock Canvas.Left="310" Canvas.Top="46" Height="23" Name="textBlock4" Text="TK QSDFWPO Aàâéèêëîïôùûüÿçæœ; Display, Aliased" TextOptions.TextFormattingMode="Display" TextOptions.TextRenderingMode="Aliased" FontSize="11" FontFamily="Times New Roman" FontWeight="Bold" />
<TextBlock Canvas.Left="309" Canvas.Top="79" Height="23" Name="textBlock5" Text="TK QSDFWPO Aàâéèêëîïôùûüÿçæœ; Display, ClearType" TextOptions.TextFormattingMode="Display" TextOptions.TextRenderingMode="ClearType" FontSize="11" FontFamily="Times New Roman" FontWeight="Bold" />
<TextBlock Canvas.Left="309" Canvas.Top="112" Height="23" Name="textBlock6" Text="TK QSDFWPO Aàâéèêëîïôùûüÿçæœ; Display, Grayscale" TextOptions.TextFormattingMode="Display" TextOptions.TextRenderingMode="Grayscale" FontSize="11" FontFamily="Times New Roman" FontWeight="Bold" />
<TextBlock Canvas.Left="188" Canvas.Top="157" FontSize="11" Height="23" Name="textBlock11" Text="TK QSDFWPO Aàâéèêëîïôùûüÿçæœ; Default" FontFamily="Times New Roman" FontWeight="Bold" />
</Canvas>
</ScrollViewer>
<TextBlock Grid.Row="1" Height="23" Name="textBlock8" Text="TK QSDFWPO Aàâéèêëîïôùûüÿçæœ; Default, static; Times New Roman, 11" FontSize="11" FontFamily="Times New Roman" FontWeight="Bold" />
<TextBlock Grid.Row="2" FontSize="11" Height="23" Name="textBlock9" Text="TK QSDFWPO Aàâéèêëîïôùûüÿçæœ; DISPLAY, static; Times New Roman, 11" TextOptions.TextFormattingMode="Display" FontFamily="Times New Roman" FontWeight="Bold" />
<TextBlock Grid.Row="3" Height="23" Name="textBlock7" Text="TK QSDFWPO Aàâéèêëîïôùûüÿçæœ; Default, static; Arial, 16" FontSize="16" FontWeight="Bold" />
<TextBlock Grid.Row="4" FontSize="16" Height="23" Name="textBlock10" Text="TK QSDFWPO Aàâéèêëîïôùûüÿçæœ; DISPLAY, static; Arial, 16" TextOptions.TextFormattingMode="Display" FontWeight="Bold" />
</Grid>
</Window>
将它粘贴到Visual Studio中时,按Ctrl键并在设计器中滚动,您会看到15岁以下的默认值是模糊的。
如果我缩放画布,DISPLAY
的选项TextFormattingMode
会被破坏。
使用ScaleTransform
时如何避免这种小的文字模糊问题?
答案 0 :(得分:1)
您可以尝试缩放字体大小,而不是在画布上使用缩放变换。虽然可能很难让文本排成一行。以您的方式缩放画布将强制进行插值,并且您将无法避免模糊文本。
说实话,我看不出两个截图之间的模糊性有什么不同。