Bad Image Quality In .NET 4.0 WPF Project

Recently at work we upgraded our .NET 3.5 SP1 app to Visual Studio 2010 .NET4.0 and all we noticed that all of our images were much more blurry after we did the upgrade.

This was quite a big deal to us since we use a lot of images. After a bit of research it turns out that that Microsoft have changed the default Scaling mode that is applied to bitmaps. It seems to be the default in .NET 3.5 was high quality and the .NET 4.0 default seems to be low quality (presumably meant as some some of performance improvement, shame you can see your images clearly though).

This affected ALL our images, I was not best pleased, luckily after a bit more digging, I found that we solve all our issues with a single Style applied to Image types, that is as follows:

    <Style TargetType="{x:Type Image}">
        <Setter Property="RenderOptions.BitmapScalingMode" 
               Value="HighQuality" />

.csharpcode, .csharpcode pre
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
background-color: #f4f4f4;
width: 100%;
margin: 0em;
.csharpcode .lnum { color: #606060; }

And that was all we had to do…Hope this helps you as much as it did us.


14 thoughts on “Bad Image Quality In .NET 4.0 WPF Project

  1. […] we did the upgrade. This was quite a big deal to us since we use a lot of images. After a bit of… [full post] sacha wpf 0 0 0 0 0 [19 Dec […]

  2. Graeme says:

    Thank you! I had the exact same problem.

  3. Barry says:

    Just an extra bit of background info: I was messing with the BitmapScalingMode settings the other day, and for a low powered machine (poor graphics card), and barely 200 images, the HighQuality setting could make the window scrolling and resizing quite jerky. With LowQuality there was no issue.

  4. Barry says:

    With a little googling, it appears that there is a CachingHint on RenderOptions that might solve my problem. I’ll investigate that when I get a chance. I’m still fooling around with WPF, so I’m not quite sure if this will work.

  5. Chen Kinnrot says:

    had the same problem, did the same solution.

    • sacha says:

      cool cool…great minds think alike, but fools seldom differ….or so the saying goes…ha ha

  6. M.Afifi says:

    Thanks a lot Sacha, you saved my day!

  7. Malte says:

    Really useful! Thanks.

  8. Mike Pelton says:

    This isn’t the first time one of your tips has helped me – I owe you at least a beer!

  9. Kraken says:

    Same problem. Thank you SO much for a solution!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: