Exemplo n.º 1
0
        public void Save(Stream outputStream)
        {
            if (_iconData != null)
            {
                ArgumentNullException.ThrowIfNull(outputStream);
                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.
                PICTDESC pictdesc = PICTDESC.CreateIconPICTDESC(Handle);
                Guid     g        = typeof(IPicture).GUID;
                IPicture picture  = OleCreatePictureIndirect(pictdesc, ref g, false);

                if (picture != null)
                {
                    try
                    {
                        ArgumentNullException.ThrowIfNull(outputStream);
                        picture.SaveAsFile(new GPStream(outputStream, makeSeekable: false), -1, out int temp);
                    }
                    finally
                    {
                        Debug.Assert(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
                        Marshal.ReleaseComObject(picture);
                    }
                }
            }
        }
Exemplo n.º 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.
                PICTDESC pictdesc = PICTDESC.CreateIconPICTDESC(Handle);
                Guid     g        = typeof(IPicture).GUID;
                IPicture picture  = OleCreatePictureIndirect(pictdesc, ref g, false);

                if (picture != null)
                {
                    try
                    {
                        // We threw this way on NetFX
                        if (outputStream == null)
                        {
                            throw new ArgumentNullException("dataStream");
                        }

                        picture.SaveAsFile(new GPStream(outputStream, makeSeekable: false), -1, out int temp);
                    }
                    finally
                    {
                        Marshal.ReleaseComObject(picture);
                    }
                }
            }
        }
Exemplo n.º 3
0
 public void SaveAsFile(IntPtr pstm, bool fSaveMemCopy, out int pcbSize)
 {
     Picture.SaveAsFile(pstm, fSaveMemCopy, out pcbSize);
 }