我使用Imaging.CreateBitmapSourceFromHIcon方法转换Icon为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;
}
在我客户的一台计算机上Imaging.CreateBitmapSourceFromHIcon抛出下一个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)
任何想法为什么会发生这种情况?(以及如何解决它)