multiple big images on canvas in WPF - rendering problems
-
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, 600DPI). 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 have tried combining 3 big sized images with IrfanView -> same problem. Adobe Photoshop on the other side can handle all 3 Images and display them though PS also consumes nearly 700 MB of phys. memory. 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
-
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, 600DPI). 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 have tried combining 3 big sized images with IrfanView -> same problem. Adobe Photoshop on the other side can handle all 3 Images and display them though PS also consumes nearly 700 MB of phys. memory. 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
Im guessing you are hitting the memory limit of the GPU. You might want to try TransformedBitmap and scale it that way, I quickly tested this with BitmapCacheOption.None and it seemed to only take up memory for the scaled image. As for the images looking wierd it may be due to a bug in WIC you may need get an updated version. Try Vista SP2 and the Platform Update For Windows Vista
modified on Wednesday, May 5, 2010 3:00 PM
-
Im guessing you are hitting the memory limit of the GPU. You might want to try TransformedBitmap and scale it that way, I quickly tested this with BitmapCacheOption.None and it seemed to only take up memory for the scaled image. As for the images looking wierd it may be due to a bug in WIC you may need get an updated version. Try Vista SP2 and the Platform Update For Windows Vista
modified on Wednesday, May 5, 2010 3:00 PM
Thank you very much for your input. I was also thinking about only having a scaled image in memory and discarding the original sized one. But this would require a lot of additional calculation. What I am trying to do is implementing an application that is capable of combining single images into one image. E.g. an architect's plan (ANSI C) is scanned in into 3 ANSI B paper sized images. Those images are now loaded into my app, repositioned and then combined. The result should be the original plan with respect to its original size, DPI etc. I was hoping there is another soluion, since Adobe Photoshop is capable of holding all 3 images in memory keeping the original sizes. But I am starting working on algorithms that will work on scaled images. best Regards Dominik