using System.Windows.Media.Imaging; using static System.Windows.Interop.Imaging; using static Vanara.PInvoke.Gdi32; using static Vanara.PInvoke.User32; namespace Vanara.PInvoke { /// Extension methods to convert GdiObj handle variants to their .NET equivalents. public static class GdiObjExtensions2 { /// Creates a from an preserving transparency, if possible. /// The SafeHBITMAP value. /// The BitmapSource instance. If is a NULL handle, is returned. public static BitmapSource ToBitmapSource(this SafeHBITMAP hbmp) => hbmp is null || hbmp.IsInvalid ? null : CreateBitmapSourceFromHBitmap(hbmp.DangerousGetHandle(), default, default, BitmapSizeOptions.FromEmptyOptions()); /// Creates a from an preserving transparency, if possible. /// The HBITMAP value. /// The BitmapSource instance. If is a NULL handle, is returned. public static BitmapSource ToBitmapSource(this in HBITMAP hbmp) => hbmp.IsNull ? null : CreateBitmapSourceFromHBitmap(hbmp.DangerousGetHandle(), default, default, BitmapSizeOptions.FromEmptyOptions()); /// Creates a managed from a HICON instance. /// A managed bitmap instance. public static BitmapSource ToBitmapSource(this in HICON hIcon) => hIcon.IsNull ? null : CreateBitmapSourceFromHIcon(hIcon.DangerousGetHandle(), default, BitmapSizeOptions.FromEmptyOptions()); /// Creates a managed from a SafeHICON instance. /// A managed bitmap instance. public static BitmapSource ToBitmapSource(this SafeHICON hIcon) => hIcon is null || hIcon.IsInvalid ? null : CreateBitmapSourceFromHIcon(hIcon.DangerousGetHandle(), default, BitmapSizeOptions.FromEmptyOptions()); } }