输出地图到文件

/// <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;

        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值