I always avoided using the metafile save method when I want to rasterize it. Instead, I draw it in Bitmap, convert and save Bitmap.
Sort of:
GraphicsUnit uPix = GraphicsUnit.Pixel; RectangleF bounds = meta.GetBounds(ref uPix); Bitmap dstBitmap = new Bitmap((int)bounds.Width, (int)bounds.Height, PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(dstBitmap); g.Clear(Color.White); g.DrawImage(meta, dstBitmap.GetBounds(ref uPix), meta.GetBounds(ref uPix), uPix); dstBitmap.Save(@"E:\output_MetaFile.tif",info,ep);
When I receive a metafile from the clipboard, I usually use this code, since it is very important to copy data from the clipboard in the case of metafiles:
if(iData.GetDataPresent(DataFormats.EnhancedMetafile)) { // Get the meta data from the clipboard IntPtr hwnd = this.Handle; if(OpenClipboard(hwnd) == false) return false; IntPtr hToTempPastedEmf = GetClipboardData(14); //CF_ENHMETAFILE=14 // Get the size of the meta data int iSize = GetEnhMetaFileBits(hToTempPastedEmf,0,IntPtr.Zero); // Copy the meta file from the clipboard (MUST remove all references to the clipboard) IntPtr hToPastedEmf = CopyEnhMetaFile(hToTempPastedEmf, new IntPtr(0)); Metafile meta = new Metafile(hToPastedEmf,false); CloseClipboard(); }
source share