private void ShowOutputFileDialog(IActiveView docActiveView, int iOutputResolution = 320) { IExport docExport; IPrintAndExport docPrintExport; IWorldFileSettings worldFileSetting; //string localFilePath, fileNameExt, newFileName, FilePath; SaveFileDialog sfd = new SaveFileDialog(); //设置对话框标题 sfd.Title = "地图输出"; //设置文件类型 sfd.Filter = "EMF(*.emf)|*.emf|AI (*.ai) |*.ai|PDF (*.pdf)|*.pdf |SVG (*.svg)| *.svg|TIFF(*.tif)|*.tif|JPEG (*.jpg)| *.jpg|PNG (*.png)| *.png"; //设置默认文件类型显示顺序 sfd.FilterIndex = 5; //保存对话框是否记忆上次打开的目录 sfd.RestoreDirectory = true; //设置默认的文件名 int start = m_mapDocumentName.LastIndexOf("\\"); int end = m_mapDocumentName.LastIndexOf("."); sfd.FileName = m_mapDocumentName.Substring(start + 1, end - start - 1); //点了保存按钮进入 if (sfd.ShowDialog() == DialogResult.OK && sfd.FileName != "") { switch (sfd.FilterIndex) { case 1: { docExport = new ExportEMFClass(); break; } case 2: { docExport = new ExportAIClass(); break; } case 3: { docExport = new ExportPDFClass(); break; } case 4: { docExport = new ExportSVGClass(); break; } case 5: { docExport = new ExportTIFFClass(); IExportTIFF exportTiff = docExport as IExportTIFF; exportTiff.GeoTiff = true; exportTiff.CompressionType = esriTIFFCompression.esriTIFFCompressionLZW; break; } //对于TIFF格式导出带有地理配准的文件 case 6: { docExport = new ExportJPEGClass(); break; } case 7: { docExport = new ExportPNGClass(); break; } default: { docExport = new ExportTIFFClass(); break; } } docPrintExport = new PrintAndExportClass(); worldFileSetting = docExport as IWorldFileSettings; string localFilePath = sfd.FileName.ToString(); //获得文件路径 //string fileNameExt = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1); //获取文件名,不带路径 docExport.ExportFileName = localFilePath; docPrintExport.Export(docActiveView, docExport, iOutputResolution, true, null); } }
/// <summary>Exports the page layout to a file.</summary> /// <param name="pageLayout">The page layout.</param> /// <param name="exportPath">The name of the output file.</param> /// <param name="exportFormat">The format of the output.</param> /// <param name="dpi">The resolution of the output files.</param> void ExportPageLayoutToFile(IPageLayout pageLayout, string exportPath, long dpi, ExportFormat exportFormat) { IExport export = null; // Get the color of the backgrounds for formats that support transparent backgrounds. IColor bgColor = null; switch (exportFormat) { case ExportFormat.GIF: case ExportFormat.PNG: IPage page = pageLayout.Page; bgColor = page.BackgroundColor; break; } // Set "export" to the proper type of Export*Class, and set parameters specific to that image type. switch (exportFormat) { case ExportFormat.AI: export = new ExportAIClass(); var ai = export as IExportAI2; //ai.EmbedFonts = true; break; case ExportFormat.EMF: export = new ExportEMFClass(); var xEmf = export as IExportEMF; //xEmf.Description = break; case ExportFormat.PS: export = new ExportPSClass(); var xPs = export as IExportPS; xPs.EmbedFonts = true; //xPs.Emulsion = //xPs.Image = //xPs.ImageCompression = esriExportImageCompression.esriExportImageCompressionNone //xPs.LanguageLevel = esriExportPSLanguageLevel.esriExportPSLevel3 break; case ExportFormat.SVG: export = new ExportSVGClass(); var xSvg = export as IExportSVG; //xSvg.Compressed = true; //xSvg.EmbedFonts = true; break; case ExportFormat.PDF: export = new ExportPDFClass(); var xPdf = export as IExportPDF; //xPdf.Compressed = true; //xPdf.EmbedFonts = true; //xPdf.ImageCompression = esriExportImageCompression.esriExportImageCompressionNone break; case ExportFormat.GIF: export = new ExportGIFClass(); IExportGIF xGif = export as IExportGIF; xGif.TransparentColor = bgColor; //xGif.BiLevelThreshold = //xGif.CompressionType = esriGIFCompression.esriGIFCompressionNone; //xGif.InterlaceMode = false; break; case ExportFormat.PNG: export = new ExportPNGClass(); IExportPNG xPng = export as IExportPNG; //xPng.BiLevelThreshold = //xPng.InterlaceMode = false; xPng.TransparentColor = bgColor; break; case ExportFormat.BMP: export = new ExportBMPClass(); IExportBMP xBmp = export as IExportBMP; //xBmp.BiLevelThreshold = //xBmp.RLECompression = true; break; case ExportFormat.JPEG: export = new ExportJPEGClass(); IExportJPEG xJpg = export as IExportJPEG; //xJpg.ProgressiveMode = false; //xJpg.Quality = 80; //The JPEG compression / image quality. Range (0..100). Default is 100 (no compression / best quality). break; case ExportFormat.TIFF: export = new ExportTIFFClass(); IExportTIFF xTif = export as IExportTIFF; //xTif.BiLevelThreshold = //xTif.CompressionType = //xTif.GeoTiff = true; //The JPEG or Deflate (depending on the Compression type) compression / image quality. Range (0..100). Default is 100 (no compression / best quality). //xTif.JPEGOrDeflateQuality = 100; break; default: const string MSG_FMT = "Support for \"{0}\" export is not yet implemented."; string message = string.Format(MSG_FMT, Enum.GetName(typeof(ExportFormat), exportFormat)); throw new NotImplementedException(message); } IEnvelope pixelEnv = new EnvelopeClass(); IEnvelope pageExt = GetPageExtent(pageLayout); IPoint upperRight = pageExt.UpperRight; pixelEnv.PutCoords(0, 0, dpi * upperRight.X, dpi * upperRight.Y); export.PixelBounds = pixelEnv; export.Resolution = dpi; export.ExportFileName = exportPath; // //(device coordinates origin is upper left, ypositive is down) tagRECT expRect; expRect.left = (int)export.PixelBounds.LowerLeft.X; expRect.bottom = (int)export.PixelBounds.UpperRight.Y; expRect.right = (int)export.PixelBounds.UpperRight.X; expRect.top = (int)export.PixelBounds.LowerLeft.Y; _app.StatusBar.set_Message(0, string.Format("exporting \"{0}\"", exportPath)); long hdc = export.StartExporting(); IActiveView av = (IActiveView)pageLayout; av.Output((int)hdc, (int)dpi, ref expRect, null, null); export.FinishExporting(); export.Cleanup(); }