Save imported image in the same format (WIP)
[master-thesis.git] / Parasitemia / ParasitemiaUI / BitmapSourceConvert.fs
1 namespace ParasitemiaUI
2
3 open System
4 open System.Runtime.InteropServices
5 open System.Windows
6 open System.Windows.Media.Imaging
7
8 open Emgu.CV
9
10 module BitmapSourceConvert =
11 [<DllImport("gdi32")>]
12 extern int DeleteObject(IntPtr o);
13
14 let ToBitmapSource (image : Image<'TColor, 'TDepth>) : BitmapSource =
15 use source = image.ToBitmap ()
16
17 let ptr : IntPtr = source.GetHbitmap ()
18
19 let bs : BitmapSource =
20 System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap
21 (
22 ptr,
23 IntPtr.Zero,
24 Int32Rect.Empty,
25 (BitmapSizeOptions.FromEmptyOptions ())
26 )
27
28 DeleteObject ptr |> ignore
29
30 bs