gpt4 book ai didi

c# - 如何在 wpf 应用程序中处理 BitmapDecoder 对象

转载 作者:行者123 更新时间:2023-11-30 20:14:05 25 4
gpt4 key购买 nike

我开发了一个 WPF 应用程序,使用 BitmapDecoder 来保存图像。在保存图像时我得到一个

insufficient memory to complete the operation exception.

代码看起来像这样:

BitmapDecoder imgDecoder = BitmapDecoder.Create(mem,
BitmapCreateOptions.IgnoreColorProfile, BitmapCacheOption.None);

我认为 BitmapDecoder 对象可能是该异常的原因;我该如何处理该对象?

最佳答案

我遇到了同样的问题。我有一个应用程序使用 BitmapDecoder 加载了数千张图像并且遇到了内存问题。我必须创建一个包装类 ImageFileHandler 来处理与 BitmapDecoder 的所有交互,然后我将我的 BitmapDecoder 实例存储在 WeakReference 中。因此,如果操作系统需要内存,我的弱引用将放弃 BitmapDecoder,然后每次我的 ImageFileHandler 需要它时,它都会在必要时创建一个新的。

关于c# - 如何在 wpf 应用程序中处理 BitmapDecoder 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/949022/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com