WPF 3.5 SP1 to fix blurry text and images

Although it is possible to display text, bitmaps, and other images in WPF you may soon realise that your display output is blurry and it is difficult for end users to use your application when a large amount of text is displayed.

 The reason for this is pixelsnapping.  Read more about this feature here: http://msdn.microsoft.com/en-us/library/aa970908.aspx .  The problem with blurry images and text is actually a WPF Design issue.  However, there is a solution coming out pretty soon; Microsoft is adding Nearest Neighbor image resampling in WPF 3.5 SP1 which will keep images from getting blurry;  they will instead get pixellated. In the mean time you could just use really large images with the default (Fant) image scaling mode so that even when magnified you would never be mapping a single texel to multiple pixels. This is what Microsoft does in Blend in several cases (like the splash screen for example) to prevent blurring with high DPI settings – they use a single large 192 DPI image which is acceptable enough when scaling.

If you absolutely must use crisp bitmaps, there are a couple of things that you can try doing:

  1.  Always use bitmaps that are the same DPI as the device on which you’re displaying. Since you don’t know at compile time what DPI your device is, in practice this means creating at least 3 copies of every bitmap: one for 96 DPI (the most common today), one for 120 DPI (the up-and-coming standard), and one for 144 DPI (common on some laptops). Of course, this still doesn’t handle every case: users are free to set whatever DPI they like on their machine and bitmaps might still look blurry in accessibility scenarios as well. You also have the problem of determining what the device DPI is in the first place – something that may not be possible in certain scenarios (e.g. Partial Trust).
  2. Ensure that the bitmap is placed an integral number of pixels from the top-left-hand corner of the device. This one is more difficult. If all your elements are fixed-layout (e.g. Canvases), you can precisely position your content relative to the window (and in V1 windows are always pixel-aligned). If you make use of any of the more complicated layout elements (Grids, DockPanels, FlowDocuments, or the like), though, you must walk up the visual tree to calculate your offset from the window origin, and you have to do this every time layout changes (for instance, every time the user scrolls through the document). 
     

Until this patch gets shipped, you may be interested in a few of these related blog posts:

-          http://blogs.msdn.com/seema/archive/2006/10/31/on-some-monitors-it-seems-that-thin-wpf-lines-are-blurred-across-two-pixels-instead-of-one-ick-how-do-i-get-sharply-rendered-lines.aspx

-          http://blogs.msdn.com/dwayneneed/archive/2007/10/05/blurry-bitmaps.aspx

SRZ080415000312

Published 07 May 2008 12:23 AM by makerofthings

Comments

# Actipro said on 15 May, 2008 12:49 PM

We've just added a PixelSnapper decorator to our WPF shared library, which helps with pixel alignment by providing options for rounding off decimal measurements of child content to integer numbers instead of decimals.  Using the PixelSnapper decorator is an easy way to keep everything crisp and clear in your WPF applications.

More info is here:

blog.actiprosoftware.com/.../How-to-prevent-blurry-images-and-lines-in-WPF.aspx

This relates directly with your second point of keeping everything an integral number of pixels from the top-left of the device.

# John Williams ok said on 20 August, 2008 07:27 AM

Pretty nice site, wants to see much more on it! :)

# retergfdbcdds said on 04 September, 2008 05:30 PM

spy vs spy reggae  <a href=soundmp3s.com/.../>JC Mazter and Noizzer</a>   hip hop influence in american culture , rap chileno

# ertgfgdfghgtrht said on 05 September, 2008 06:52 AM

audio video codecs download for windows xp x64  <a href= soundmp3s.com/.../lenny-dee >Lenny Dee song lyrics</a>   west african celtic music

# iyuukuykkyut said on 05 September, 2008 11:18 AM

baby frog prince costume  <a href= royalmp3.net/.../atone-discography >Listen free Atone Music Online</a>   enya orinoco flow techno

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Search

Go

This Blog

Sponsors





Archives

Syndication

 
Page view counter