简体   繁体   English

BitmapImage内存不足

[英]Out of Memory with BitmapImage

I'm trying to developp an app to take and print photos with Visual Studio 2013. 我正在尝试开发使用Visual Studio 2013拍摄和打印照片的应用程序。

The app is divide in 2 project : 该应用程序分为2个项目:

  • First the client, it take 4 photos and send their pathfiles. 首先,客户端需要拍摄4张照片并发送其路径文件。

  • The second is the server. 第二个是服务器。 When there is a connection, he show the 4 photos. 建立连接后,他会显示4张照片。 Then the user can choose a frame, a quantity and print his photos. 然后,用户可以选择框架,数量并打印其照片。

There is a problem with the loading: 加载有问题:

            BitmapImage _img1 = new BitmapImage();
            _img1.BeginInit();
            _img1.CacheOption = BitmapCacheOption.OnLoad;
            _img1.UriSource = new Uri(_images[0]);
            _img1.EndInit();
            img1.Source = _img1;

            BitmapImage _img2 = new BitmapImage();
            _img2.BeginInit();
            _img2.CacheOption = BitmapCacheOption.OnLoad;
            _img2.UriSource = new Uri(_images[1]);
            _img2.EndInit();
            img2.Source = _img2;

            BitmapImage _img3 = new BitmapImage();
            _img3.BeginInit();
            _img3.CacheOption = BitmapCacheOption.OnLoad;
            _img3.UriSource = new Uri(_images[2]);
            _img3.EndInit();
            img3.Source = _img3;

            BitmapImage _img4 = new BitmapImage();
            _img4.BeginInit();
            _img3.CacheOption = BitmapCacheOption.OnLoad;
            _img4.UriSource = new Uri(_images[3]);
            _img4.EndInit();
            img4.Source = _img4;

I've try with "BitmapCacheOption.OnDemand". 我尝试使用“ BitmapCacheOption.OnDemand”。 When the program start, memory consumption is 3Go. 程序启动时,内存消耗为3Go。 After few minutes, it increase to 6Go. 几分钟后,它增加到6Go。

When the outofmemoryexception is thrown, it comes to PresentationCore.dll 抛出outofmemoryexception时,它出现在PresentationCore.dll中

I've looking ofr the consumption, and at each loop of the program, the comsumption increase of 0,4Go. 我一直在寻找消耗量,并且在程序的每个循环中,消耗量增加了0.4Go。

WIthout show the photos, the app is stable. 不显示照片,应用程序稳定。

I've try with Bitmap and BitmapImage, GC.Collect and DeleteObject of gdi32.dll, the problem is the same. 我尝试使用gdi32.dll的Bitmap和BitmapImage,GC.Collect和DeleteObject,问题是相同的。

Is there a way to dispose all the resources? 有没有办法处置所有资源?

Sorry for my english 对不起我的英语不好

You are caching the whole bitmap in memory - BitmapCacheOption.OnLoad. 您正在将整个位图缓存在内存中-BitmapCacheOption.OnLoad。 Try using None or OnDemand instead of OnLoad. 尝试使用None或OnDemand代替OnLoad。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Windows Phone 8的内存不足异常BitMapImage - Out of Memory exception BitMapImage for Windows Phone 8 如何从内存中而不是文件系统中的另一个BitmapImage调整BitmapImage的大小 - How to resize a BitmapImage from another BitmapImage in memory and not on filesystem Windows Phone 8中BitmapImage / Image控件的内存消耗 - Memory consumption of BitmapImage/Image control in Windows Phone 8 将BitmapImage设置为null时无法释放内存 - Memory not being relieved when setting BitmapImage to null 将 BitmapImage 转换为 Byte 后如何清除内存 - How can i clear the memory after converting BitmapImage to Byte 用BitmapImage设置Image的Source后如何释放内存? - How to free memory after set Image's Source with BitmapImage? WPF:使用 ValueConverter 为 ImageSource 创建 BitmapImage 的内存影响 - WPF: Memory implications of using ValueConverter to create BitmapImage for ImageSource 加载BitmapImage在WP 8.1 RT中占用大量内存 - Loading BitmapImage occupies lot of memory in WP 8.1 RT 使用BitmapImage.SetSource打开大图像 - 内存不足 - Opening large Images using BitmapImage.SetSource - Insufficient Memory Exception 如何将BitmapImage从内存保存到WPF C#中的文件中? - How do I save a BitmapImage from memory into a file in WPF C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM