Пример #1
0
        private static Image GetImageFromParams(object pict, IntPtr handle, int pictype, IntPtr paletteHandle, int width,
		                                        int height)
        {
            switch (pictype)
            {
                case -1:
                    return null;

                case 0:
                    return null;

                case 1:
                    return Image.FromHbitmap(handle, paletteHandle);

                case 2:
                    {
                        var wmfHeader = new WmfPlaceableFileHeader();
                        wmfHeader.BboxRight = (short) width;
                        wmfHeader.BboxBottom = (short) height;
                        var metafile = new Metafile(handle, wmfHeader, false);
                        return (Image) RuntimeHelpers.GetObjectValue(metafile.Clone());
                    }
                case 4:
                    {
                        var metafile2 = new Metafile(handle, false);
                        return (Image) RuntimeHelpers.GetObjectValue(metafile2.Clone());
                    }
            }
            throw new Exception("AXUnknownImage");
        }
Пример #2
0
		public void Metafile_String ()
		{
			string filename = getInFile (WmfPlaceable);
			Metafile mf = new Metafile (filename);
			Metafile clone = (Metafile) mf.Clone ();
		}
Пример #3
0
        //*************************************************************************
        //  Method: TryPasteEnhancedMetafile()
        //
        /// <summary>
        /// Attempts to paste an enhanced metafile from the clipboard into the
        /// PictureBox.
        /// </summary>
        ///
        /// <returns>
        /// true if an enhanced metafile was pasted into the PictureBox.
        /// </returns>
        ///
        /// <remarks>
        /// If the clipboard contains an enhanced metafile, this method pastes it
        /// into the PictureBox and returns true.  Otherwise, false is returned.
        /// </remarks>
        //*************************************************************************
        public Boolean TryPasteEnhancedMetafile()
        {
            // This interop code was adapted from the following post:
            //
            // http://www.eggheadcafe.com/community/aspnet/12/10018506/
            // how-to-paste--metafile-fr.aspx
            //
            // NOTE: Do not try this non-interop technique:
            //
            //     Object oData = Clipboard.GetData(DataFormats.EnhancedMetafile);
            //
            //     if (oData != null)
            //     {
            //         System.Drawing.Imaging.Metafile oMetafile =
            //             (System.Drawing.Imaging.Metafile)oData;
            //     }
            //
            // When pasting from a chart image copied from Excel, the GetData()
            // call crashes Excel.  Although the Clipboard class reports that the
            // DataFormats.EnhancedMetafile format is available (along with
            // "Preferred DropEffect", "InShellDragLoop", and "MetaFilePict"), it
            // does not seem to be the format that the .NET Framework is expecting.
            // Using the interop technique below works properly, however.

            Boolean bReturn = false;

            if ( OpenClipboard(this.Handle) )
            {
            if ( IsClipboardFormatAvailable(CF_ENHMETAFILE) )
            {
                IntPtr oPtr = GetClipboardData(CF_ENHMETAFILE);

                if ( !oPtr.Equals( new IntPtr(0) ) )
                {
                    Metafile oMetafile = new Metafile(oPtr, true);

                    this.Image = (Metafile)oMetafile.Clone();
                    bReturn = true;
                }
            }

            CloseClipboard();
            }

            return (bReturn);
        }