Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Windows.Media.Imaging;
|
---|
6 | using System.Windows;
|
---|
7 | using System.Windows.Controls;
|
---|
8 | using System.ComponentModel;
|
---|
9 |
|
---|
10 | namespace 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.