/// <summary> /// 输出图片 /// </summary> /// <param name="activeView"></param> /// <param name="filename"></param> /// <param name="format"></param> /// <param name="resolution"></param> public static void ExportRasterFile(IActiveView activeView, string filename, string format, double resolution) { if (activeView == null || filename.Length == 0) { return; } double screenResolution = resolution; double outputResolution = resolution; IExport export = null; switch (format) { case "PDF": export = new ExportPDFClass(); IExportVectorOptions exportVectorOptions = export as IExportVectorOptions; exportVectorOptions.PolygonizeMarkers = true; IExportPDF exportPDF = export as IExportPDF; exportPDF.EmbedFonts = true; break; case "BMP": export = new ExportBMPClass(); break; case "JPG": export = new ExportJPEGClass(); if (filename.IndexOf("彩信") != -1) { IExportJPEG exportJPEG = export as IExportJPEG; exportJPEG.Quality = 70; outputResolution = 70.0; } break; case "PNG": export = new ExportPNGClass(); break; case "TIF": export = new ExportTIFFClass(); break; case "GIF": export = new ExportGIFClass(); break; case "EMF": export = new ExportEMFClass(); break; case "SVG": export = new ExportSVGClass(); break; case "AI": export = new ExportAIClass(); break; case "EPS": export = new ExportPSClass(); break; } IGraphicsContainer docGraphicsContainer; IElement docElement; IOutputRasterSettings docOutputRasterSettings; IMapFrame docMapFrame; IActiveView tmpActiveView; IOutputRasterSettings doOutputRasterSettings; if (activeView is IMap) { doOutputRasterSettings = activeView.ScreenDisplay.DisplayTransformation as IOutputRasterSettings; doOutputRasterSettings.ResampleRatio = 3; } else if (activeView is IPageLayout) { doOutputRasterSettings = activeView.ScreenDisplay.DisplayTransformation as IOutputRasterSettings; doOutputRasterSettings.ResampleRatio = 4; //and assign ResampleRatio to the maps in the PageLayout. docGraphicsContainer = activeView as IGraphicsContainer; docGraphicsContainer.Reset(); docElement = docGraphicsContainer.Next(); int c = 0; while (docElement != null) { c += 1; if (docElement is IMapFrame) { docMapFrame = docElement as IMapFrame; tmpActiveView = docMapFrame.Map as IActiveView; docOutputRasterSettings = tmpActiveView.ScreenDisplay.DisplayTransformation as IOutputRasterSettings; docOutputRasterSettings.ResampleRatio = 1; } docElement = docGraphicsContainer.Next(); } docMapFrame = null; docGraphicsContainer = null; tmpActiveView = null; } else { docOutputRasterSettings = null; } //end export.ExportFileName = filename; export.Resolution = outputResolution; tagRECT exportRECT = activeView.ExportFrame; exportRECT.right = (int)(exportRECT.right * (outputResolution / screenResolution)); exportRECT.bottom = (int)(exportRECT.bottom * (outputResolution / screenResolution)); IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom); export.PixelBounds = envelope; int hDC = export.StartExporting(); activeView.Output(hDC, Convert.ToInt32(export.Resolution), ref exportRECT, null, null); export.FinishExporting(); export.Cleanup(); }