1 //----------------------------------------------------------------------------
2 // Copyright (C) 2004-2015 by EMGU Corporation. All rights reserved.
3 //----------------------------------------------------------------------------
6 using System
.Runtime
.InteropServices
;
8 using System
.Windows
.Media
;
9 using System
.Windows
.Media
.Imaging
;
10 using System
.Windows
.Shapes
;
15 public static class BitmapSourceConvert
18 /// Delete a GDI object
20 /// <param name="o">The poniter to the GDI object to be deleted</param>
21 /// <returns></returns>
23 private static extern int DeleteObject(IntPtr o
);
26 /// Convert an IImage to a WPF BitmapSource. The result can be used in the Set Property of Image.Source
28 /// <param name="image">The Emgu CV Image</param>
29 /// <returns>The equivalent BitmapSource</returns>
30 public static BitmapSource
ToBitmapSource(IImage image
)
32 using (System
.Drawing
.Bitmap source
= image
.Bitmap
)
34 IntPtr ptr
= source
.GetHbitmap(); //obtain the Hbitmap
36 BitmapSource bs
= System
.Windows
.Interop
.Imaging
.CreateBitmapSourceFromHBitmap(
40 System
.Windows
.Media
.Imaging
.BitmapSizeOptions
.FromEmptyOptions());
42 DeleteObject(ptr
); //release the HBitmap