Imaging.CreateBitmapSourceFromHIcon抛出COMException

时间:2014-04-24 12:46:03

标签: c# wpf winforms-interop system.drawing.imaging

我使用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)

任何想法为什么会发生这种情况? (以及如何解决它)

0 个答案:

没有答案