tags:

views:

64

answers:

2

Is there anything I can do to help manage the sheer amount of memory WPF uses to render huge images - potentially anything up to 10,000 x 10,000?

I need to maintain the quality as zooming is key, but loading the Image control seems to require anything from 50 - 700MB of memory usage :S

I'm not doing anything particularly clever with loading the image at the moment:

BitmapImage imageSource = new BitmapImage();
imageSource.BeginInit();
imageSource.UriSource = new Uri(imageUrl, UriKind.Absolute);
imageSource.CacheOption = BitmapCacheOption.OnLoad;
imageSource.EndInit();

image.Source = imageSource;
+1  A: 

You can use BitmapImage.DecodePixelHeight or BitmapImage.DecodePixelWidth to render the image at a lower quality optimized for the size of your dialog. In XAML it looks like this:

<Image>
    <Image.Source>
        <BitmapImage UriSource="http://server/image.jpg" DecodePixelWidth="400" />
    </Image.Source>
</Image>
Jakob Christensen
A: 

So there appears to be a bit of a memory leak/issue with the networking stack as downloading the image to a local disk then loading that appears to reduce memory usage by about 40%.

I've now read numerous blogs confirming this. I've also put in a form of lazy-load using the DecodePixelWidth/Height that Jakob mentioned but am pleased to have found a way of loading the full quality image with a considerably smaller memory footprint :)

Tom Allen