private static IImage GetImage(StreamOnFile stream) { IImagingFactory factory = null; try { factory = (IImagingFactory)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("327ABDA8-072B-11D3-9D7B-0000F81EF32E"))); if (factory != null) { IImage imagingImage; uint result = factory.CreateImageFromStream(stream, out imagingImage); if (result == BitmapProperties.S_OK) { return(imagingImage); } } } catch (COMException) { } catch (IOException) { } finally { if (factory != null) { Marshal.ReleaseComObject(factory); } } return(null); }