System.Drawing.Bitmap m_Bitmap = new System.Drawing.Bitmap("c:\temp\test.jpg", false);
IntPtr ip = m_Bitmap.GetHbitmap();
BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
ip, IntPtr.Zero, Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
DeleteObject(ip);
imageLarge.Source = bitmapSource;
其中DeleteObject的声明如下:IntPtr ip = m_Bitmap.GetHbitmap();
BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
ip, IntPtr.Zero, Int32Rect.Empty,
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
DeleteObject(ip);
imageLarge.Source = bitmapSource;
[DllImport("gdi32")]
static extern int DeleteObject(IntPtr o);
使用过System.Drawing.Bitmap后一定要用DeleteObject释放掉对象,不然内存不释放,很快系统内存就消耗光了。