none
.net 4.0 wpf image resizing/scaling looks horrible RRS feed

  • Question

  • I've recently upgraded a project from .net 3.5 to .net 4.0.  There were two breaking changes one of which I'll discuss here.

    In .net 3.5, when images are sized down because they don't fit into the space alloted them they still look great.

    Imagine you have:

    <Window x:Class="WPF4Issues.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="MainWindow">
     <Window.Resources>
      <ResourceDictionary Source="LookAndFeel.xaml"/>
     </Window.Resources>
     <Grid>
      <Grid.RowDefinitions>
       <RowDefinition Height="*"/>
       <RowDefinition Height="*"/>
      </Grid.RowDefinitions>
      <Grid.ColumnDefinitions>
       <ColumnDefinition Width="*"/>
       <ColumnDefinition Width="*"/>
      </Grid.ColumnDefinitions>
      <StackPanel Grid.Row="0" Grid.Column="0" MinWidth="20" MinHeight="20" />
      <Image Grid.Row="0" Grid.Column="1" Source="Smiley.png"/>
      <StackPanel Grid.Row="1" Grid.Column="0" MinWidth="20" MinHeight="20"/>
      <StackPanel Grid.Row="1" Grid.Column="1" MinWidth="20" MinHeight="20" />
     </Grid>
    </Window>

    where Smiley.png is a big image (1024 x 1024).  In .net 3.5 Smiley.png would look great no matter what you sized the window or other controls in the grid to.  He would resize as needed when changing the window size and always look great (even if he got really small).

    If I change my target framework to .net 4.0 Smiley.png looks horrible when he's small, the lines don't look smooth and he looks horribly pixelated.  In my current project we have thousands of images and they all look bad in .net 4.0 but great in .net 3.5.  Any suggestions?

    Thanks,
    Brian
    Friday, May 7, 2010 3:03 PM

Answers

All replies