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. ...
随机推荐
- 学习Linux第四天
---恢复内容开始--- 1.常用的命令: reset 清屏 leave +hhmm 建立离开提醒 sudo apt-get yum 安装yum程序 sudo su 切换root身份 see test ...
- zoj 2760 How Many Shortest Path 最大流
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1760 Given a weighted directed graph ...
- 【BZOJ】【1449】【JSOI2009】球队收益
网络流/费用流/二分图最小权匹配 题解:http://blog.csdn.net/huzecong/article/details/9119741 太神了!由于一赢一输不好建图,就先假设全部都输,再将 ...
- js添加事件、移除事件、阻止冒泡、阻止浏览器默认行为等写法(兼容IE/FF/CHROME)
转自:http://blog.csdn.net/itchiang/article/details/7769341 添加事件 var addEvent = function( obj, type, ...
- 【转载】一淘技术专家王晓哲:Nginx_lua的测试及选择
对于Web高性能服务器上的选择,这个是很多人头痛的问题.其实Apache.lighttpd.Nginx都用他们优点,在什么情况下我们如何去选择适合自己的Web高性能服务器,如何去搭建一个适合自己的架构 ...
- Sqlite基础及其与SQLServer语法差异
1 TOP 这是一个大家经常问到的问题,例如在SQLSERVER中可以使用如下语句来取得记录集中的前十条记录: SELECT TOP 10 * FROM [index] ORDER BY indexi ...
- Extjs文本输入框
var loginForm = Ext.create('Ext.form.Panel', { title: '单行输入', renderTo: Ext.getBody( ...
- 制作类似DataGrid自定义控件
首先看一下.net自带的DataGrid,想想如何应该怎样才能实现那样的展现形式. 1)需要以网格形式显示内容. 2)网格的宽度.高度可以定义. 3)可以显示滚动条. 4)单击可以选中某个单元格. 当 ...
- ACE 1.1.9 发布,开源云端代码编辑器
点这里 ACE 1.1.9 发布,开源云端代码编辑器 oschina 发布于: 2015年04月06日 (1评) 分享到: 收藏 +25 4月18日 武汉 源创会开始报名,送华为开发板 ACE ...
- Linux网络编程7——使用TCP实现双方聊天
思路 主线程负责发送消息,另一线程负责接收消息.服务端和客户端均是如此. 注意 当A方close掉用于通信的socket端口后,该端口是不会立即关闭的.因为此时可能B方的信息还没send完.因此,此时 ...