I use Imaging.CreateBitmapSourceFromHIcon
method to convert Icon
to BitmapSource
:
private static System.Windows.Media.ImageSource loadWpfImageSource(Icon icon, Size size)
{
if (icon != null)
{
return Imaging.CreateBitmapSourceFromHIcon(icon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
}
return null;
}
At one of my client's computer Imaging.CreateBitmapSourceFromHIcon
throws the next COMException
:
System.Runtime.InteropServices.COMException (0x8007057A): Wrong pointer descriptor. (Exception from HRESULT: 0x8007057A)
at System.Windows.Interop.InteropBitmap..ctor(IntPtr hicon, Int32Rect sourceRect, BitmapSizeOptions sizeOptions)
at System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(IntPtr icon, Int32Rect sourceRect, BitmapSizeOptions sizeOptions)
Any ideas why could this happen? (And how to fix it)
User contributions licensed under CC BY-SA 3.0