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);
一下就好了
內存就不會爆炸了