/// <summary> /// Converts an enhanced metafile to a windows metafile picture (CF_MFPICT). Please note that the provided enhanced metafile should neither contain /// transparancies nor splines. Thus it is best if the provided enhanced metafile contains only an embedded bitmap in 24bppRGB format. /// </summary> /// <param name="hEmf">The handle to the enhanced metafile.</param> /// <param name="docSizeX">The document size x in points.</param> /// <param name="docSizeY">The document size y in points.</param> /// <returns>Handle to a windows meta file picture (CF_MFPICT).</returns> public static IntPtr ConvertEnhancedMetafileToWindowsMetafilePict(IntPtr hEmf, double docSizeX, double docSizeY) { byte[] buffer = ConvertEnhancedMetafileToWindowsMetafileBytes(hEmf); // Get a handle to the converted metafile. IntPtr hmf = Gdi32Func.SetMetaFileBitsEx((uint)buffer.Length, buffer); // Convert the Metafile to a METAFILEPICT. IntPtr hMem = Kernel32Func.GlobalAlloc(GlobalAllocFlags.GHND, Marshal.SizeOf(typeof(METAFILEPICT))); var mfp = new METAFILEPICT() { mm = MappingMode.MM_ANISOTROPIC, xExt = PointToHimetric(docSizeX), yExt = PointToHimetric(docSizeY), hMF = hmf }; Marshal.StructureToPtr(mfp, Kernel32Func.GlobalLock(hMem), false); Kernel32Func.GlobalUnlock(hMem); return(hMem); }
/// <summary> /// Saves a metafile to disk. /// </summary> /// <param name="hEnhMetafile">The handle to the enhanced metafile to save.</param> /// <param name="filename">The filename under which the metafile should be saved.</param> public static void SaveMetafileToDisk(IntPtr hEnhMetafile, string filename) { // Export metafile to an image file Gdi32Func.CopyEnhMetaFile(hEnhMetafile, filename); }