输出地图到文件,导出地图
/// <summary>
/// 输出地图到文件
/// </summary>
/// <param name="resolution">像素</param>
/// <param name="format">格式(后缀名,如jpg)</param>
/// <param name="fileName">完整文件名</param>
/// <returns>成功返回true,失败返回false</returns>
public static bool ExportMapToFile(string format, string fileName)
{
//先刷新布局
IPageLayout pageLayout = ArcMap.Document.PageLayout;
IActiveView activeView = (IActiveView)pageLayout;
activeView.Refresh();
IExport pExport = null;
IWorldFileSettings pWorldFile = null;
IExportImage pExportType;
IEnvelope pDriverBounds = null;
tagRECT userRECT = new tagRECT();
IEnvelope pEnv = new EnvelopeClass();
switch (format)
{
case "jpg":
pExport = new ExportJPEGClass();
break;
case "bmp":
pExport = new ExportBMPClass();
break;
case "gif":
pExport = new ExportGIFClass();
break;
case "tif":
pExport = new ExportTIFFClass();
break;
case "png":
pExport = new ExportPNGClass();
break;
case "emf":
pExport = new ExportEMFClass();
break;
case "pdf":
pExport = new ExportPDFClass();
break;
case ".ai":
pExport = new ExportAIClass();
break;
case "svg":
pExport = new ExportSVGClass();
break;
default:
pExport = new ExportJPEGClass();
break;
}
int iScreenResolution = 96;
int iOutputResolution = 300;
pExport.ExportFileName = fileName;
pExport.Resolution = iOutputResolution;
pExportType = pExport as IExportImage;
pExportType.ImageType = esriExportImageType.esriExportImageTypeTrueColor;
pEnv = ArcMap.Document.ActiveView.Extent;
pWorldFile = (IWorldFileSettings)pExport;
pWorldFile.MapExtent = pEnv;
pWorldFile.OutputWorldFile = false;
userRECT.top = 0;
userRECT.left = 0;
//userRECT.right = 0;
//userRECT.bottom = 0;
userRECT.right = activeView.ExportFrame.right * (iOutputResolution / iScreenResolution);
userRECT.bottom = activeView.ExportFrame.bottom * (iOutputResolution / iScreenResolution);
pDriverBounds = new EnvelopeClass();
pDriverBounds.PutCoords(userRECT.top, userRECT.bottom, userRECT.right, userRECT.top);
pExport.PixelBounds = pDriverBounds;
ITrackCancel pTrackCancel = new TrackCancelClass();
ArcMap.Document.ActiveView.Output(pExport.StartExporting(), iOutputResolution, ref userRECT, ArcMap.Document.ActiveView.Extent, pTrackCancel);
pExport.FinishExporting();
pExport.Cleanup();
return true;
}
public static bool Export(IMap map, IExport pExport, string path)
{
IActiveView pActiveView;
IEnvelope pPixelBoundsEnv;
int iOutputResolution;
int iScreenResolution;
int hdc;
pActiveView = map as IActiveView;
pExport.ExportFileName = path;
iScreenResolution = 96;
iOutputResolution = 300;
pExport.Resolution = iOutputResolution;
tagRECT pExportFrame;
pExportFrame = pActiveView.ExportFrame;
tagRECT exportRECT;
exportRECT.left = 0;
exportRECT.top = 0;
exportRECT.right = pActiveView.ExportFrame.right * (iOutputResolution / iScreenResolution);
exportRECT.bottom = pActiveView.ExportFrame.bottom * (iOutputResolution / iScreenResolution);
pPixelBoundsEnv = new EnvelopeClass();
pPixelBoundsEnv.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
pExport.PixelBounds = pPixelBoundsEnv;
hdc = pExport.StartExporting();
pActiveView.Output(hdc, (int)pExport.Resolution, ref exportRECT, null, null);
pExport.FinishExporting();
pExport.Cleanup();
return true;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现