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(); }
求高手指点~
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;
}