WPF CreateBitmapSourceFromHBitmap()内存泄漏
我需要逐个像素地绘制图像并将其显示在WPF中。我试图通过使用System.Drawing.Bitmap然后使用CreateBitmapSourceFromHBitmap()创建BitmapSource一个WPF图像控件来做到这一点。我在某处有内存泄漏,因为当CreateBitmapSourceFromBitmap()重复调用时,内存使用率会上升,并且在应用程序结束之前不会下降。如果我不打电话CreateBitmapSourceFromBitmap(),内存使用量没有明显变化。
for (int i = 0; i < 100; i++){
var bmp = new System.Drawing.Bitmap(1000, 1000);
var source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
bmp.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
source = null;
bmp.Dispose();
bmp = null;}我该怎么做才能释放BitmapSource记忆?
翻阅古今
慕标琳琳