using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Media.Imaging; using System.Windows; using System.Windows.Controls; using System.ComponentModel; namespace HeuristicLab.MainForm.WPF { internal static class ImageConverter { public static Image Win32Image2WPFImage(System.Drawing.Image image) { if (image == null) return null; System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(image); IntPtr hBitmap = bitmap.GetHbitmap(); BitmapSource source = null; try { source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); return new Image() { Source = source }; } catch (Win32Exception) { return null; } finally { NativeMethods.DeleteObject(hBitmap); } } } }