--- /dev/null
+namespace ParasitemiaUI
+
+open System
+open System.Runtime.InteropServices
+open System.Windows
+open System.Windows.Media.Imaging
+
+open Emgu.CV
+
+module BitmapSourceConvert =
+ [<DllImport("gdi32")>]
+ extern int DeleteObject(IntPtr o);
+
+ let ToBitmapSource (image : Image<'TColor, 'TDepth>) : BitmapSource =
+ use source = image.ToBitmap ()
+
+ let ptr : IntPtr = source.GetHbitmap ()
+
+ let bs : BitmapSource =
+ System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap
+ (
+ ptr,
+ IntPtr.Zero,
+ Int32Rect.Empty,
+ (BitmapSizeOptions.FromEmptyOptions ())
+ )
+
+ DeleteObject ptr |> ignore
+
+ bs