multiple big images on canvas in WPF - rendering problems

Apr 6 2010 9:48 AM
I am trying to put several images dynamically onto a canvas. The images are of bigger size (e.g. 9 MB on disc, 200 MB of physical memory when decoded, resolution of 10200 x 7019).
If I add 2 images, everything is working fine. If I try to add another image, the Image is there on the canvas (meaning it reacts on mouse events) but it is not rendered - meaning it is invisible.  I have about 1 GB of free physical memory available. When 2 images are loaded I still have 600 MB of free physical memory - but I cant load any more images. I tried to set the images' DecodeBitmapWith/Height attributes to have a smaller rendersize, but images are rendered black or look weird.  Image.Rendersize attribute doesnt work in this context.

I assume it has something to do with memory management. For better understanding here is my code:

ofd = new OpenFileDialog();
if ((bool)ofd.ShowDialog(this))
{
string[] images = ofd.FileNames;
foreach (string image in images)
{
Uri imgsource = new Uri(image);
BitmapImage bim = new BitmapImage();
bim.BeginInit();
//bim.DecodePixelWidth = 3509;
bim.DecodePixelHeight = 10200;
bim.CacheOption = BitmapCacheOption.OnLoad;
bim.UriSource = imgsource;
bim.EndInit();
Image img = new Image();
img.Source = bim
canvas1.Children.Add(img);
img.AllowDrop = true;
Canvas.SetLeft(img, (canvas1.Children.Count)* 20);
Canvas.SetTop(img, (canvas1.Children.Count) * 20);
}

I hope anyone can help me with this.
Thanks in advance and best regards
Nick

Answers (2)