/// <include file='doc\Icon.uex' path='docs/doc[@for="Icon.Save"]/*' /> /// <devdoc> /// Saves this image to the given output stream. /// </devdoc> public void Save(Stream outputStream) { if (_iconData != null) { outputStream.Write(_iconData, 0, _iconData.Length); } else { // Ideally, we would pick apart the icon using // GetIconInfo, and then pull the individual bitmaps out, // converting them to DIBS and saving them into the file. // But, in the interest of simplicity, we just call to // OLE to do it for us. // SafeNativeMethods.IPicture picture; SafeNativeMethods.PICTDESC pictdesc = SafeNativeMethods.PICTDESC.CreateIconPICTDESC(Handle); Guid g = typeof(SafeNativeMethods.IPicture).GUID; picture = SafeNativeMethods.OleCreatePictureIndirect(pictdesc, ref g, false); if (picture != null) { int temp; try { picture.SaveAsFile(new UnsafeNativeMethods.ComStreamFromDataStream(outputStream), -1, out temp); } finally { Marshal.ReleaseComObject(picture); } } } }
public void Save(Stream outputStream) { if (this.iconData != null) { outputStream.Write(this.iconData, 0, this.iconData.Length); } else { SafeNativeMethods.PICTDESC pictdesc = SafeNativeMethods.PICTDESC.CreateIconPICTDESC(this.Handle); Guid gUID = typeof(SafeNativeMethods.IPicture).GUID; SafeNativeMethods.IPicture o = SafeNativeMethods.OleCreatePictureIndirect(pictdesc, ref gUID, false); if (o != null) { try { int num; o.SaveAsFile(new System.Drawing.UnsafeNativeMethods.ComStreamFromDataStream(outputStream), -1, out num); } finally { Marshal.ReleaseComObject(o); } } } }