Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Imaging.CreateBitmapSourceFromHIcon抛出COMException_C#_Wpf_Winforms Interop_System.drawing.imaging - Fatal编程技术网

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
的方式转换
图标
,图标将无法转换?