I just Upgraded my WPF application from .NET 3.5 to .NET 4 and Now My Images Look Terrible–A Visual Guide to the BitmapScalingMode property.

Although this has been mentioned in other places already, I thought it was worth calling this out specifically as a change from .NET 3.5 to .NET 4. With the release of .NET 4 Microsoft chose to change the default RenderOptions.BitmapScalingMode value from HighQuality to LowQuality. In many other areas the API changes when moving to .NET 4 were ‘opt-in’ so this was a little out-of-the-ordinary.

Below is a visual guide to the different types of image scaling modes in WPF v4, along with their names (although as Steve points out in the comments below there are really only 3 options since HighQuality is an alias for Fant, and LowQuality is an alias for Linear).

BitmapScalingModes

This image is 2 x larger than normal, with no interpolation applied during the resize, so it exaggerates the differences between the different scaling modes. How nice an image will look when a particular scaling mode is applied depends largely on the image, so I’ve included the code below. You can plug in an image of your choosing and see how the different scaling modes apply to it.

<Window x:Class="DotNet4ImageScalingMode.MainWindow"
        xmlns="
http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid Margin="5">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
            <ColumnDefinition />
            <ColumnDefinition />
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
       
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
       
        <Image Source="winlogo.png" />
        <Image Source="winlogo.png" RenderOptions.BitmapScalingMode="HighQuality" Grid.Column="1" />
        <Image Source="winlogo.png" RenderOptions.BitmapScalingMode="LowQuality" Grid.Column="2" />
        <Image Source="winlogo.png" RenderOptions.BitmapScalingMode="Fant" Grid.Column="0" Grid.Row="2" />
        <Image Source="winlogo.png" RenderOptions.BitmapScalingMode="Linear" Grid.Column="1" Grid.Row="2" />
        <Image Source="winlogo.png" RenderOptions.BitmapScalingMode="NearestNeighbor" Grid.Column="2" Grid.Row="2" />

        <TextBlock Text="Default" Grid.Row="1" />
        <TextBlock Text="HighQuality" Grid.Row="1" Grid.Column="1" />
        <TextBlock Text="LowQuality" Grid.Row="1" Grid.Column="2" />
        <TextBlock Text="Fant" Grid.Row="3" Grid.Column="0" />
        <TextBlock Text="Linear" Grid.Row="3" Grid.Column="1" />
        <TextBlock Text="NearestNeighbor" Grid.Row="3" Grid.Column="2" />
    </Grid>
</Window>

Comments

Steve
There are only 3 different values:

public enum BitmapScalingMode { Fant = 2, HighQuality = 2, Linear = 1, LowQuality = 1, NearestNeighbor = 3, Unspecified = 0 }

2/12/2010 5:16:32 AM
Joseph Cooney
Steve - right, but since the API has all the different names I thought I’d show them all.
2/12/2010 6:15:47 AM
alvinashcraft.com
Pingback from alvinashcraft.com

Dew Drop – December 3, 2010 | Alvin Ashcraft's Morning Dew

3/12/2010 8:08:36 AM
topsy.com
Pingback from topsy.com

Twitter Trackbacks for

    I just Upgraded my WPF application from .NET 3.5 to .NET 4 and Now My Images Look Terrible–A Visual Guide to the BitmapScalingMode property. 
    [learnwpf.com]
    on Topsy.com</div>
3/12/2010 4:11:41 PM
Pete Brown
@Jack What kind of authoritative info are you looking for? I wrote something small about it a while back: http://10rem.net/blog/2010/05/01/crappy-image-resizing-in-wpf-try-renderoptionsbitmapscalingmode But the post here is more in-depth. Pete Brown Microsoft Community Program Manager
6/12/2010 12:57:17 PM
Microsoft Weblogs
Windows Client Developer Roundup 051 for 12/6/2010 This is Windows Client Developer Roundup #51. The First Birthday edition of the roundup. The first edition
6/12/2010 1:32:08 PM
ispey.com
Pingback from ispey.com Windows Client Developer Roundup 051 for 12/6/2010 · Computer Hardware
6/12/2010 7:41:58 PM