public static byte[] FormatToEmf(IList<Figure> figures, DPoint screenMM, DPoint deviceRes) { if (figures.Count > 0) { DRect r = GetBounds(figures); EmfGraphics dg = new EmfGraphics(r, screenMM, deviceRes); foreach (Figure f in figures) f.Paint(dg); return dg.EmfData; } return null; }
private bool ExportImage(IList<DEngine> expEngines) { bool result = false; FolderBrowserDialog fbd = new FolderBrowserDialog(); if (fbd.ShowDialog() == DialogResult.OK) { result = true; try { // setup progress form ProgressForm pf = new ProgressForm(); pf.Text = WbLocale.ExportingToImages; pf.Shown += delegate(object s, EventArgs e) { string fileNameTemplate; if (rbPng.Checked) fileNameTemplate = Path.GetFileNameWithoutExtension(docFileName) + "{0}.png"; else fileNameTemplate = Path.GetFileNameWithoutExtension(docFileName) + "{0}.emf"; DPrintViewer dvPrint = new DPrintViewer(); foreach (DEngine de in expEngines) { DBitmap bmp = WFHelper.MakeBitmap((int)de.PageSize.X, (int)de.PageSize.Y); DGraphics dg; if (rbPng.Checked) dg = WFHelper.MakeGraphics(bmp); else dg = new EmfGraphics(new DRect(0, 0, de.PageSize.X, de.PageSize.Y), WorkBookUtils.GetScreenMM(), WorkBookUtils.GetScreenRes()); dvPrint.Paint(dg, de.BackgroundFigure, de.Figures); if (rbPng.Checked) bmp.Save(Path.Combine(fbd.SelectedPath, string.Format(fileNameTemplate, engines.IndexOf(de) + 1))); else ((EmfGraphics)dg).SaveToFile(Path.Combine(fbd.SelectedPath, string.Format(fileNameTemplate, engines.IndexOf(de) + 1))); dg.Dispose(); bmp.Dispose(); } pf.Close(); System.Diagnostics.Process.Start(fbd.SelectedPath); }; pf.ShowDialog(); } catch (Exception e) { result = false; MessageBox.Show(WbLocale.ERROR, e.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); } } return result; }