WPF BitmapImage内存 [英] WPF BitmapImage Memory
本文介绍了WPF BitmapImage内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在使用C#WPF中的位图图像,我遇到了以下问题,我希望有人可以提供帮助。下面的代码是我如何将位图图像分配给位图,然后分配给ImageControl。问题在于我将这段代码用于许多位图图像并且它们似乎留在内存中......如何以正确的方式从内存中删除位图图像。请帮助!
Hi, I am currently working with Bitmap Images in C# WPF, and I have run into the following problem and I was hoping someone could help. the code below is how I assign a bitmap image to a bitmap and then to a ImageControl. The problem comes in that im using this code for many bitmap images and they seem to stay in memory... How do I remove bitmap images from memory the correct way. Please Help!
BitmapImage logo = new BitmapImage();
logo.BeginInit();
logo.CreateOptions = BitmapCreateOptions.IgnoreColorProfile;
logo.UriSource = new Uri(f.FullName);
displayImage.Source = logo;
logo.EndInit();
提前致谢:)
Thanks in advance :)
推荐答案
通过在我的项目中添加以下代码,
logo.DecodePixelWidth = 100;
logo.DecodePixelHeight = 100;
它工作得更好,并且在使用大约700张图像时更加内存友好:)
By adding the following Code to my project,
logo.DecodePixelWidth = 100;
logo.DecodePixelHeight = 100;
it works alot better and is alot more memory friendly when using around about 700 images :)
BitmapImage imageDocumento = new BitmapImage ();
imageDocumento.BeginInit();
imageDocumento.UriSource = new Uri(@c:\ image.png);
imageDocumentoDA1.CacheOption = BitmapCacheOption.OnLoad;
imageDocumentoDA1.EndInit();
BitmapImage imageDocumento = new BitmapImage();
imageDocumento.BeginInit();
imageDocumento.UriSource = new Uri(@"c:\image.png");
imageDocumentoDA1.CacheOption = BitmapCacheOption.OnLoad;
imageDocumentoDA1.EndInit();
这篇关于WPF BitmapImage内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文