AE 将地图导出为图片的两种方法
/// <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 将地图导出为图片的两种方法的更多相关文章
- AE工程渲染的时间缓慢,两种方法减少对AE工程渲染的时间!
AE工程渲染的时间缓慢,两种方法减少对AE工程渲染的时间!3秒的片头,渲染时间竟然要花1个多小时,很多新手都产生过这样的疑问?是哪里不对吗?如何才能减少渲染视频的时间?且听我一一道来.主要原因是:工程 ...
- UIImage加载图片的两种方法区别
Apple官方的文档为生成一个UIImage对象提供了两种方法加载图片: 1. imageNamed,其参数为图片的名字: 2. imageWithContentsOfFile,其参数也是图片文件的路 ...
- input上传图片(file),预览图片的两种方法。blob与base64编码
上传图片时一般都需要预览,我一般用这两种方法来实现.base64编码可以直接上传到后台,后台解析下,得到的文件就会比较小了,省去了压缩图片这一步了. //获取对象input file 的图片地址,放进 ...
- VC下加载JPG/GIF/PNG图片的两种方法
转载自:http://blog.sina.com.cn/s/blog_6582aa410100huil.html 仅管VC有提供相应的API和类来操作bmp位图.图标和(增强)元文件,但却不支持jpg ...
- .NET CORE 2.1 导出excel文件的两种方法
最近在做 MVC 项目的时候遇到项目的导出,下面总结下两种导出到excel 的方法 第一种方法: 将文件写到本地,然后返回这个File 或者返回这个 File 的绝对地址 其中 _hostingE ...
- python 读取并显示图片的两种方法
在 python 中除了用 opencv,也可以用 matplotlib 和 PIL 这两个库操作图片.本人偏爱 matpoltlib,因为它的语法更像 matlab. 一.matplotlib 1. ...
- python实现读取并显示图片的两种方法
https://www.cnblogs.com/lantingg/p/9259840.html 在 python 中除了用 opencv,也可以用 matplotlib 和 PIL 这两个库操作图片. ...
- android 图片叠加效果——两种方法
效果图: 第一种: 第二种: 第一种是通过canvas画出来的效果: public void first(View v) { // 防止出现Immutable bitmap passed to Can ...
- ios图片拉伸两种方法
UIImage *image = [UIImage imageNamed:@"qq"]; 第一种: // 左端盖宽度 NSInteger leftCapWidth = image. ...
随机推荐
- web开发--文档下载
GOOGLE在线文档下载地址分享(GOOGLE的文档地址暂不能用了,会放在其它位置..) GOOGLE的在线文档功能好象挂掉了...等找个其它存放的位置把这些文档再上传上去... 存在GOOGLE里面 ...
- Posix线程编程指南(5) 杂项
在Posix线程规范中还有几个辅助函数难以归类,暂且称其为杂项函数,主要包括pthread_self().pthread_equal()和pthread_once()三个,另外还有一个LinuxThr ...
- ACM--South Pacific 2012
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=5 ...
- 生成中文版JavaDoc
RT. 在用IDEA生成中文版JavaDoc时,出现如下问题: java.lang.IllegalArgumentException at sun.net.www.ParseUtil.decode(P ...
- NYOJ-20 吝啬的国度 AC 分类: NYOJ 2014-01-23 12:18 200人阅读 评论(0) 收藏
#include<cstdio> #include<cstring> #include<vector> using namespace std; int pre[1 ...
- shader 的 nounroll
刚刚解决了一个特别坑的问题. 客户有个需求 需要shader里面 loop 的iterator数量 在运行时确定.z 这样对于里面存在 sample的loop就会被force unroll但因为co ...
- 录制iphone手机视频
1: 升级自己的手机到ios8, 同时mac os也要升级到10.10 2: 用usb数据线将手机连上电脑. 3: 打开quicktime player创建新movie 4: 选择手机作为音频.视频源 ...
- html5 webApp常用Meta标签
Html5 webApp常用Meta标签 <meta charset="UTF-8"> <meta name="viewport" conte ...
- Keil中的code关键字
一般说来,我们在C语言中定义的每一个变量初始化后都会占用一定的内存(RAM)空间.但是在keil中提供了一个特殊的关键字“code”,这个关键字在标准C中是没有的.其语法举例如下: unsigned ...
- Scrum敏捷软件开发之技术实践——测试驱动开发TDD
重复无聊的定义 测试驱动开发,英文全称Test-Driven Development,简称TDD,是一种不同于传统软件开发流程的新型的开发方法.它要求在编写某个功能的代码之前先编写测试代码,然后只编写 ...