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);
             }
         }
     }
 }
示例#2
0
        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.PICTDESC pictdesc = SafeNativeMethods.PICTDESC.CreateIconPICTDESC(Handle);
                Guid g = typeof(SafeNativeMethods.IPicture).GUID;
                SafeNativeMethods.IPicture picture = SafeNativeMethods.OleCreatePictureIndirect(pictdesc, ref g, false);

                if (picture != null)
                {
                    try
                    {
                        picture.SaveAsFile(new UnsafeNativeMethods.ComStreamFromDataStream(outputStream), -1, out int temp);
                    }
                    finally
                    {
                        Marshal.ReleaseComObject(picture);
                    }
                }
            }
        }
示例#3
0
 /// <devdoc>
 ///     Saves a picture from the requested stream.
 /// </devdoc>
 internal void SavePicture(Stream stream)
 {
     if (stream == null)
     {
         throw new ArgumentException(SR.GetString(SR.InvalidArgument, "stream", "null"));
     }
     try {
         int temp;
         picture.SaveAsFile(new UnsafeNativeMethods.ComStreamFromDataStream(stream), -1, out temp);
     }
     catch (Exception e) {
         Debug.Fail(e.ToString());
         throw new InvalidOperationException(SR.GetString(SR.InvalidPictureFormat));
     }
 }