I am working on a WPF application that has several canvases and many buttons. User mode loads images to change the button background.
This is the code in which I load the image into a BitmapImage object
bmp = new BitmapImage();
bmp.BeginInit();
bmp.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
bmp.CacheOption = BitmapCacheOption.OnLoad;
bmp.UriSource = new Uri(relativeUri, UriKind.Relative);
bmp.EndInit();
and in EndInit () application memory grows a lot.
One thing that makes you think better (but doesn't really fix the problem) adds
bmp.DecodePixelWidth = 1024;
1024 is my maximum canvas size. But I should only do this for images with a width greater than 1024 - so how can I get the width before EndInit ()?
source
share