2010-03-31 8 views
11

Con WPF4 puede tener texto no borrosa añadiendo TextOptions.TextFormattingMode = "Visualización" y TextOptions.TextRenderingMode = "alias" para su xaml:TextOptions.TextFormattingMode con FormattedText

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

Esto funciona muy bien para me excepción de cuando dibujo de texto con DrawingContext.DrawText así:

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)); 
} 

¿Cómo puedo dibujar texto no borrosa con FormattedText? es decir, quiero TextOptions.TextFormattingMode = "Display" y TextOptions.TextRenderingMode = "Aliased" para ser utilizado.

Respuesta

12

Hay un constructor sobrecargado para FormattedText que permite especificar un 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)); 
} 
+3

Esta respuesta es correcta, ¿Por qué alguien lo votó? – asktomsk

+0

+1. Estoy de acuerdo, esta respuesta es definitivamente correcta y no puedo ver una razón para un voto negativo. No especifica cómo configurar 'TextRenderingMode' aunque –

Cuestiones relacionadas