Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OKB/HeuristicLab.MainForm.WPF/ImageConverter.cs @ 4695

Last change on this file since 4695 was 4311, checked in by swagner, 14 years ago

Integrated OKB clients for HL 3.3 (#1166)

File size: 949 bytes
RevLine 
[4311]1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Windows.Media.Imaging;
6using System.Windows;
7using System.Windows.Controls;
8using System.ComponentModel;
9
10namespace HeuristicLab.MainForm.WPF {
11  internal static class ImageConverter {
12    public static Image Win32Image2WPFImage(System.Drawing.Image image) {
13      if (image == null)
14        return null;
15      System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(image);
16      IntPtr hBitmap = bitmap.GetHbitmap();
17      BitmapSource source = null;
18      try {
19        source = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
20          hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
21        return new Image() { Source = source };
22      } catch (Win32Exception) {
23        return null;
24      } finally {
25        NativeMethods.DeleteObject(hBitmap);
26      }
27    }
28  }
29}
Note: See TracBrowser for help on using the repository browser.