mercredi 1 avril 2015

WPF Image RenderOptions.BitmapScalingMode.LowQuality consumes 10x more memory than HighQuality

I have an image which is about 5k x 5k pixels.

The image contains a LayoutTransform with a ScaleTransform.



<Image x:Name="image" Source="{Binding ImageSource, Mode=OneWay}" Width="{Binding ImageWidth, Mode=OneWay}" Height="{Binding ImageHeight, Mode=OneWay}" Visibility="{Binding ImageVisibility, Mode=OneWay}" RenderOptions.BitmapScalingMode="HighQuality" RenderOptions.EdgeMode="Aliased">
<Image.LayoutTransform>
<ScaleTransform ScaleX="{Binding ScaleValue, Mode=OneWay}" ScaleY="{Binding ScaleValue, Mode=OneWay}"/>
</Image.LayoutTransform>
</Image>


Since scaling the image is very slow due to the HighQuality option, I decided to set it to LowQuality during the scaling process. As it turns out the LowQuality option consumes much more memory than HighQuality as you can see in the screenshot.



RenderOptions.SetBitmapScalingMode(image, BitmapScalingMode.LowQuality); //Reduce quality during resize to improve performance (or not :()




The memory peak after setting it to Low is not temporary - it stays until the application is closed. A second or third resize operation has no effect on the peak.



I believe the Image Control caches the image of some sort - not sure though.

I am also familliar with a memory leak which can happen if a BitmapImage is not manually destroyed but I think this is not the problem here since the peak happens during the RenderOption-change.



Any ideas are very much appreciated enter image description here


Aucun commentaire:

Enregistrer un commentaire