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:

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

.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.

Advertisements

14 Comments

  1. 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.

    Reply

  2. 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.

    Reply

Leave a Reply

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

WordPress.com Logo

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

Google+ photo

You are commenting using your Google+ 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 )

w

Connecting to %s