1

I am rendering text but the output of small fontsizes is quite bad. This seems to be an old wpf rendering issue. But there should be solutions available, see WPF Blurry fonts issue- Solutions.

As far as i understand it comes down to setting the TextOptions.TextRenderingMode to TextRenderingMode.Aliased in order to get sharper output. I tried doing that, but the result did not change.

My question is, on wich dependency object do i need to set the renderoption? I am doing it like this:

  var text = new FormattedText(...);
  var textGeometry = text.BuildGeometry(position);
  var drawing = new GeometryDrawing(brush, null, textGeometry);
  TextOptions.SetTextFormattingMode(drawing, TextFormattingMode.Display);
  TextOptions.SetTextRenderingMode(drawing, TextRenderingMode.Aliased);
  theDrawing.Children.Add(drawing);

Later i am using a RenderTargetBitmap in order to render the drawings. That bitmap has also set all renderoptions like posted above. Finally this bitmap gets displayed within a Imagecontrol (all UI elements have Textoptions + Renderoptions set aswell) But no sucess... Maybe my problem is that i am using a GeometryDrawing and thus my text does not get recognized as text...

Thanx for all your input!

Edit:

UI Code:

  TextOptions.SetTextFormattingMode(this, TextFormattingMode.Display);
  TextOptions.SetTextFormattingMode(this.ImageControl, TextFormattingMode.Display);

  TextOptions.SetTextRenderingMode(this, TextRenderingMode.Aliased);
  TextOptions.SetTextRenderingMode(this.ImageControl, TextRenderingMode.Aliased);
brun0
  • 77
  • 8
  • 1
    Because you are painting the text you are losing any ability to re-render the text the problem is likely to be because the final image is being scaled – MikeT Apr 13 '17 at 08:44
  • By painting you mean the step when the bitmap renders the drawing - correct? – brun0 Apr 13 '17 at 08:49
  • 1
    Yes you will always get lower quality text when you embed it in an image as it stops being text and becomes a picture subject to stretching, shrinking and lossy encoders – MikeT Apr 13 '17 at 08:56
  • Ok, but how could i avoid that renderstep if i want to use it as a Image.Source on the UI? Is there a different way of handing the (not rendered) drawings to the UI? – brun0 Apr 13 '17 at 09:00
  • 1
    i would suggest storing the text as meta data and then placing it in controls over the image, the only time you should need to manually render a UI is if your saving screenshots – MikeT Apr 13 '17 at 09:49
  • Thanx for your input MikeT! Guess i have to overthink our concept. One goal was to have the possibility to use the wpf render output bitmap in other environments if needed. Thats the reason why i rendered a bitmap manually. Anyway, your postings pointed me in the right direction... – brun0 Apr 13 '17 at 10:13
  • A closing note: Indeed the blurriness was a result of a bitmap scaling. I implemented a solution that uses drawingVisuals as childs of a Visualhost UI element (thus renounce the bitmap rendering) -> voila`, all fonts are sharp! – brun0 Apr 18 '17 at 08:06
  • As stated, the scaling of the bitmap was leading to blurry fonts. I looked closer into that, as i thought my Imagecontrol and my bitmap had exactly the same size. But, as i learned, that was not the case. See also: http://stackoverflow.com/questions/16045697/how-do-i-make-a-wpf-image-control-to-have-same-dimensions-as-its-bitmapimage-s Setting Stretch to "none" on the Imagecontrol can do the trick... – brun0 Apr 18 '17 at 08:51

0 Answers0