I have the following hierarchy structure
Item (object)
- List<Item>Children (property)
- ItemType (property)
ItemType (object)
- ImageSource Icon (property)
My Icons are stored as .png resource files. So, I can't load them directly. Instead, I need to convert them from a Bitmap over to a BitmapSource. They can then be used as the Icon (ImageSource).
Question is, does anyone have a good way in managed code to do this conversion? I currently do this using interop but I would think there is a better way. My current conversion method:
Item (object)
- List<Item>Children (property)
- ItemType (property)
ItemType (object)
- ImageSource Icon (property)
My Icons are stored as .png resource files. So, I can't load them directly. Instead, I need to convert them from a Bitmap over to a BitmapSource. They can then be used as the Icon (ImageSource).
Question is, does anyone have a good way in managed code to do this conversion? I currently do this using interop but I would think there is a better way. My current conversion method:
public static BitmapSource LoadBitmap(Bitmap source) |
{ |
return System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( |
source.GetHbitmap(), |
IntPtr.Zero, Int32Rect.Empty, |
System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions()); |
} |