C# Imaging.CreateBitmapSourceFromHIcon抛出COMException
我使用C# Imaging.CreateBitmapSourceFromHIcon抛出COMException,c#,wpf,winforms-interop,system.drawing.imaging,C#,Wpf,Winforms Interop,System.drawing.imaging,我使用Imaging.CreateBitmapSourceFromHIcon方法将图标转换为位图源: private static System.Windows.Media.ImageSource loadWpfImageSource(Icon icon, Size size) { if (icon != null) { return Imaging.CreateBitmapSourceFromHIcon(icon.Handle,
Imaging.CreateBitmapSourceFromHIcon
方法将图标
转换为位图源
:
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)
你知道为什么会这样吗?(以及如何修复)错误消息错误。这是一个低级Windows错误,错误代码1402,错误\u无效\u光标\u句柄,“无效光标句柄”。图标和光标几乎无法区分。一个简单的解释是图标损坏或无效,这当然可能发生。@Hans Passant:如果图标损坏,是否意味着如果我通过使用
MemoryStream
的方式转换图标
,图标将无法转换?