Answered by:
.net 4.0 wpf image resizing/scaling looks horrible

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,
BrianFriday, May 7, 2010 3:03 PM
Answers
-
It seems the WPF team has decided to default RenderOptions.BitmapScalingMode to low in .net 4.0 when it was defaulted to high in .net 3.5.
See:
This means to make the scaling look nice again I'll have to go where ever an image is set and do:
<Image RenderOptions.BitmapScalingMode="HighQuality" Grid.Row="0" Grid.Column="1" Source="Smiley.png"/>
- Marked as answer by Jay_WangMicrosoft employee Thursday, May 13, 2010 10:46 AM
Friday, May 7, 2010 3:30 PM -
Hi,
Yes you're right, this is a change between 3.5 and 4.0.
In pre-4.0 versions, the default value BitmapScalingMode.Unspecified equals to BitmapScalingMode.Fant, which results high quality but lower performance.
http://msdn.microsoft.com/en-us/library/system.windows.media.bitmapscalingmode(VS.90).aspx
In 4.0, the default value BitmapScalingMode.Unspecified equals to BitmapScalingMode.Linear, to provide better performance.
http://msdn.microsoft.com/en-us/library/system.windows.media.renderoptions.aspx
There was another discussion on why making this change: Does WPF 4.0 default to lower-quality scaling algorithm?
Hope this helps.
Regards,
Jie
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
If you have any feedback, please tell us.
The All-In-One Code Framework Project
My Blog (in Simplified Chinese)- Marked as answer by Jay_WangMicrosoft employee Thursday, May 13, 2010 10:46 AM
Monday, May 10, 2010 2:21 AM
All replies
-
It seems the WPF team has decided to default RenderOptions.BitmapScalingMode to low in .net 4.0 when it was defaulted to high in .net 3.5.
See:
This means to make the scaling look nice again I'll have to go where ever an image is set and do:
<Image RenderOptions.BitmapScalingMode="HighQuality" Grid.Row="0" Grid.Column="1" Source="Smiley.png"/>
- Marked as answer by Jay_WangMicrosoft employee Thursday, May 13, 2010 10:46 AM
Friday, May 7, 2010 3:30 PM -
Hi,
Yes you're right, this is a change between 3.5 and 4.0.
In pre-4.0 versions, the default value BitmapScalingMode.Unspecified equals to BitmapScalingMode.Fant, which results high quality but lower performance.
http://msdn.microsoft.com/en-us/library/system.windows.media.bitmapscalingmode(VS.90).aspx
In 4.0, the default value BitmapScalingMode.Unspecified equals to BitmapScalingMode.Linear, to provide better performance.
http://msdn.microsoft.com/en-us/library/system.windows.media.renderoptions.aspx
There was another discussion on why making this change: Does WPF 4.0 default to lower-quality scaling algorithm?
Hope this helps.
Regards,
Jie
MSDN Subscriber Support in Forum
If you have any feedback on our support, please contact msdnmg@microsoft.com
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
If you have any feedback, please tell us.
The All-In-One Code Framework Project
My Blog (in Simplified Chinese)- Marked as answer by Jay_WangMicrosoft employee Thursday, May 13, 2010 10:46 AM
Monday, May 10, 2010 2:21 AM -
How can I change the RenderOptions.BitmapScalingMode on the application icon which is now shown in the task-bar jagged and ugly?Saturday, December 11, 2010 9:46 AM