在ArcGIS的开发中,我们经常需要将当前地图打印(或是转出)到图片文件中。将Map或Layout中的图象转出有两种方法,一种为通过IActiveView的OutPut函数,另外一种是通过IExport接口来实现。第一种方法导出速度较快,实现也比较方便,但该方法对于图片的行或列数超过10000左右时,导出经常会失败(具体原因未知),第二种方法导出速度较慢,但效果较好,且可以在导出过程中通过ITrackCancel来中止导出操作。
   通过IActiveView的方式导出是通过创建Graphics对象来实现,具体示例代码如下:

/// <summary>

/// 将Map上指定范围(该范围为规则区域)内的内容输出到Image,注意,当图片的行数或列数超过10000左右时,出现原因示知的失败

/// </summary>

/// <param name="pMap">需转出的MAP</param>
/// <param name="outRect">输出的图片大小</param>
/// <param name="pEnvelope">指定的输出范围(为Envelope类型)</param>
/// <returns>输出的Image 具体需要保存为什么格式,可通过Image对象来实现</returns>
public static Image SaveCurrentToImage(IMap pMap, Size outRect, IEnvelope pEnvelope)
 {
      //赋值
      tagRECT rect = new tagRECT();
      rect.left = rect.top = 0;
      rect.right = outRect.Width;
      rect.bottom = outRect.Height;
      try
      {                
          //转换成activeView,若为ILayout,则将Layout转换为IActiveView
          IActiveView pActiveView = (IActiveView)pMap;
          // 创建图像,为24位色
          Image image = new Bitmap(outRect.Width, outRect.Height); //, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
          System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image);

// 填充背景色(白色)
          g.FillRectangle(Brushes.White, 0, 0, outRect.Width, outRect.Height);

int dpi = (int)(outRect.Width / pEnvelope.Width);

pActiveView.Output(g.GetHdc().ToInt32(), dpi, ref rect, pEnvelope, null);

g.ReleaseHdc();

return image;
     }

catch (Exception excp)
     {
        MessageBox.Show(excp.Message + "将当前地图转出出错,原因未知", "出错提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

return null;
      }
 }

通过IExport接口实现的导出,也需要通过IActiveView的OutPut来实现,但其转出句柄为IExport的StartExporting函数返回的DC,具体示例代码如下:

//输出当前地图至指定的文件    
public void ExportMapExtent(IActiveView pView, Size outRect,string outPath)
{           
    try
    {
        //参数检查
        if pView == null )
        {
            throw new Exception("输入参数错误,无法生成图片文件!");
        }  
        //根据给定的文件扩展名,来决定生成不同类型的对象
        ESRI.ArcGIS.Output.IExport export = null;
        if (outPath.EndsWith(".jpg"))
        {
            export = new ESRI.ArcGIS.Output.ExportJPEGClass();
        }
        else if (outPath.EndsWith(".tiff"))
        {
            export = new ESRI.ArcGIS.Output.ExportTIFFClass();
        }
        else if (outPath.EndsWith(".bmp"))
        {
            export = new ESRI.ArcGIS.Output.ExportBMPClass();
        }
        else if (outPath.EndsWith(".emf"))
        {
            export = new ESRI.ArcGIS.Output.ExportEMFClass();
        }
        else if (outPath.EndsWith(".png"))
        {
            export = new ESRI.ArcGIS.Output.ExportPNGClass();
        }
        else if (outPath.EndsWith(".gif"))
        {
            export = new ESRI.ArcGIS.Output.ExportGIFClass();
        }

export.ExportFileName = outPath;
        IEnvelope pEnvelope = pView.Extent;
        //导出参数           
        export.Resolution = 300;
        tagRECT exportRect = new tagRECT();
        exportRect.left = exportRect.top = 0;
        exportRect.right = outRect.Width;
        exportRect.bottom = (int)(exportRect.right * pEnvelope.Height / pEnvelope.Width);
        ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
        //输出范围
        envelope.PutCoords(exportRect.left, exportRect.top, exportRect.right, exportRect.bottom);
        export.PixelBounds = envelope;
        //可用于取消操作
        ITrackCancel pCancel = new CancelTrackerClass();
        export.TrackCancel = pCancel;
        pCancel.Reset();
        //点击ESC键时,中止转出
        pCancel.CancelOnKeyPress = true;
        pCancel.CancelOnClick = false;
        pCancel.ProcessMessages = true;
        //获取handle
        System.Int32 hDC = export.StartExporting();
        //开始转出
        pView.Output(hDC, (System.Int16)export.Resolution, ref exportRect, pEnvelope, pCancel);
        bool bContinue = pCancel.Continue();
        //捕获是否继续
        if (bContinue)
        {                              
            export.FinishExporting();
            export.Cleanup();
        }
        else
        {                  
            export.Cleanup();
        }
        bContinue = pCancel.Continue();               
    }
    catch (Exception excep)
    {
        //错误信息提示
    }

}

AE 将地图导出为图片的两种方法的更多相关文章

  1. AE工程渲染的时间缓慢,两种方法减少对AE工程渲染的时间!

    AE工程渲染的时间缓慢,两种方法减少对AE工程渲染的时间!3秒的片头,渲染时间竟然要花1个多小时,很多新手都产生过这样的疑问?是哪里不对吗?如何才能减少渲染视频的时间?且听我一一道来.主要原因是:工程 ...

  2. UIImage加载图片的两种方法区别

    Apple官方的文档为生成一个UIImage对象提供了两种方法加载图片: 1. imageNamed,其参数为图片的名字: 2. imageWithContentsOfFile,其参数也是图片文件的路 ...

  3. input上传图片(file),预览图片的两种方法。blob与base64编码

    上传图片时一般都需要预览,我一般用这两种方法来实现.base64编码可以直接上传到后台,后台解析下,得到的文件就会比较小了,省去了压缩图片这一步了. //获取对象input file 的图片地址,放进 ...

  4. VC下加载JPG/GIF/PNG图片的两种方法

    转载自:http://blog.sina.com.cn/s/blog_6582aa410100huil.html 仅管VC有提供相应的API和类来操作bmp位图.图标和(增强)元文件,但却不支持jpg ...

  5. .NET CORE 2.1 导出excel文件的两种方法

    最近在做 MVC 项目的时候遇到项目的导出,下面总结下两种导出到excel 的方法 第一种方法: 将文件写到本地,然后返回这个File 或者返回这个 File 的绝对地址  其中  _hostingE ...

  6. python 读取并显示图片的两种方法

    在 python 中除了用 opencv,也可以用 matplotlib 和 PIL 这两个库操作图片.本人偏爱 matpoltlib,因为它的语法更像 matlab. 一.matplotlib 1. ...

  7. python实现读取并显示图片的两种方法

    https://www.cnblogs.com/lantingg/p/9259840.html 在 python 中除了用 opencv,也可以用 matplotlib 和 PIL 这两个库操作图片. ...

  8. android 图片叠加效果——两种方法

    效果图: 第一种: 第二种: 第一种是通过canvas画出来的效果: public void first(View v) { // 防止出现Immutable bitmap passed to Can ...

  9. ios图片拉伸两种方法

    UIImage *image = [UIImage imageNamed:@"qq"]; 第一种: // 左端盖宽度 NSInteger leftCapWidth = image. ...

随机推荐

  1. RobotFramework-调用.py文件

    RobotFramework-调用.py文件,直接运行: 注意:文件路径的\全部换成好了/

  2. cygwin chmod 失效

    问题背景 为了在 Cygwin 下使用之前最喜爱的 screen 命令, 安装 Cygwin 时就选上了 screen 来运行一把 ganiks.liu@MAMIS-Gaiks-Liu /tmp $ ...

  3. Codeforces Round #131 (Div. 2) E. Relay Race dp

    题目链接: http://codeforces.com/problemset/problem/214/E Relay Race time limit per test4 secondsmemory l ...

  4. Codeforces Round #353 (Div. 2) C Money Transfers

    题目链接: http://www.codeforces.com/contest/675/problem/C 题意: 给一个数组,每个数与他相邻的数相连,第一个与最后一个相连,每个数的数值可以左右移动, ...

  5. 请实现一个函数用来判断字符串是否表示数值(包括整数和小数)。例如,字符串"+100","5e2","-123","3.1416"和"-1E-16"都表示数值。 但是"12e","1a3.14","1.2.3","+-5"和"12e+4.3"都不是。

    // test20.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...

  6. poj 3009 Curling 2.0

    题目来源:http://poj.org/problem?id=3009 一道深搜题目,与一般搜索不同的是,目标得一直往一个方向走,直到出界或者遇到阻碍才换方向. 1 #include<iostr ...

  7. Leetcode#129 Sum Root to Leaf Numbers

    原题地址 二叉树的遍历 代码: vector<int> path; int sumNumbers(TreeNode *root) { if (!root) ; ; path.push_ba ...

  8. [百度空间] [转]DLL地狱及其解决方案

    DLL地狱及其解决方案 原作者:Ivan S Zapreev 译者:陆其明概要 本文将要介绍DLL的向后兼容性问题,也就是著名的“DLL Hell”问题.首先我会列出自己的研究结果,其中包括其它一些研 ...

  9. javascript禁止复制网页内容,兼容三大浏览器

    javascript禁止复制网页内容可以通过以下方式实现:禁止鼠标右键+禁止选中文本. 代码很简单,只需要在head标签的javascript内加入以下两行代码即可. document.onconte ...

  10. Python编程指南 chapter 1

    1.python使用方括号[]来存取一个序列中的某个数据项,像字符串.列表等包含若干数据项的序列都采用这种方法. 2.强制类型转换,int('24234'),str(235) 3.python中没有变 ...