首页 新闻 会员 周边 捐助

WPF控件异常Object must be initialized before operation can be performed.怎么解决啊?

0
[已关闭问题] 关闭于 2011-12-08 11:15

Object must be initialized before operation can be performed. ---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x88982F0C

报错代码出处如下:

  var bytes = File.ReadAllBytes(imageFile);    

            if (bytes == null || bytes.Length == 0)           

     {                    return null;                }   

             using (var ms = new MemoryStream(bytes))         

       {                  

  var decoder = BitmapDecoder.Create(ms, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);                  

  return decoder.Frames.FirstOrDefault();                }

求高手指点~

好 奇的主页 好 奇 | 菜鸟二级 | 园豆:205
提问于:2011-07-01 10:33
< >
分享
所有回答(1)
0

using (var ms = new MemoryStream(bytes))
{
BitmapSource bitSrc = null;
Bitmap img = new Bitmap(ms);
var hBitmap = img.GetHbitmap();

try
{
bitSrc = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
hBitmap,
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
}
catch (Win32Exception)
{
bitSrc = null;
}

return bitSrc;
}

好 奇 | 园豆:205 (菜鸟二级) | 2011-12-08 11:14
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册