【发布时间】:2012-01-30 00:09:38
【问题描述】:
我正在使用一个使用 BitmapSource 的 WPF 应用程序,但我需要进行一些操作 但我需要对 System.Drawing.Bitmaps 进行一些操作。
应用程序的内存使用量在运行时会增加。
我已将内存泄漏缩小到此代码:
private BitmapSource BitmaptoBitmapsource(System.Drawing.Bitmap bitmap)
{
BitmapSource bms;
IntPtr hBitmap = bitmap.GetHbitmap();
BitmapSizeOptions sizeOptions = BitmapSizeOptions.FromEmptyOptions();
bms = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, sizeOptions);
bms.Freeze();
return bms;
}
我认为这是未正确处理的非托管内存,但我似乎无法找到手动执行此操作的方法。提前感谢您的帮助!
亚历克斯
【问题讨论】:
标签: c# wpf memory bitmap unmanaged