首页 > Windows开发 > 详细

WPF bitmap转bitmapimage 使用 CreateBitmapSourceFromHBitmap内存泄漏

时间:2016-04-21 22:00:30      阅读:279      评论:0      收藏:0      [点我收藏+]
IntPtr f = bmp.GetHbitmap();
img.Source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(f, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

这里要是多次使用 不及时释放内存就会爆炸~

解决办法:

用windows下的GDI32.DLL类

使用办法:

先引用system.runtime.serialzation类

如果解决方案配置是在Debug下面的话

把gdi32.dll放在bing\debug

然后新建一个类

  static  class Class1
    {
      [System.Runtime.InteropServices.DllImport("gdi32.dll")]
      public static extern bool DeleteObject(IntPtr o);
    }

然后每次在转化以后 

  Class1.DeleteObject(f);

一下就好了

内存就不会爆炸了 


WPF bitmap转bitmapimage 使用 CreateBitmapSourceFromHBitmap内存泄漏

原文:http://www.cnblogs.com/yuanjunqq/p/5418872.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!