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
Woody WoodPosted Feb 7, 2018, 7:31 AM
Dominik GruberPosted May 3, 2010, 3:58 AM
Edit1:
Additional information: the images have been scanned at 600 dpi.
When loaded into BitmapImage the origianal Image is downscaled to 96 dpi. How can I keep the original size of the image?
I tried setting the DecodePixelWidth and -Height properties to the original size (7019x10200) of the image, but WPF keeps downscaling it to 1123.04X1632.
Edit2:
Kind of a solution to the DPI problem:
The BitmapImage is the source of an Image element. The Image.Width and Image.Height properties are set to BitmapImage.PixelWidth and BitmapImage.PixelHeight and the Image.Stretch property is set to Uniform. This renders the Image to its original PixelSize. But nonetheless the original Image is first downscaled to fit the 96 dpi screen, then stretched again to fit the ImageElement...if you have a better solution please feel free to post it here.
Thanks
Nick