转自:http://blog.sina.com.cn/s/blog_4c5f70df0100a0ti.html
在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)
{
//错误信息提示
}
}
分享到:
相关推荐
在ArcGIS Engine中,将当前地图范围导出为任意像素大小的图片。 QQ;77837769 共同学习、研究、进步 更多资源请访问 http://www.gislover.net/blog
ArcGIS Engine开发课程设计源码下载 ArcGIS Engine 开发 源码
详细介绍了如何在ArcGIS Engine开发中加载MDB中的数据, 带有C#开发的代码
ArcGIS Engine 开发入门介绍 ArcGIS Engine开发入门介绍
包括开发基础组件对象模型、ArcGIS Engine介绍、基于.NET的ArcGIS Engine的开发,ArcGIS Engine中的控件、框架控件介绍、控件使用实例等,为以后应用ArcGIS Engine的各种接口,快速地实现系统的开发打下坚实的基础;...
arcgisengine二次开发实现专题地图,源代码写的比较详细
Arcgis engine 9.3 中文环境 新鲜出炉 用AE9.3开发的程序,由于客户要求中文,我用了许多AE 中的很多bean(比如toolbarbean),发布后是英文的。 于是百度,Google,搜AE9.3 中文环境,找了一下午都没有找到。 ...
ArcGIS Engine 开发技术ESRI官方代码
用ArcGIS绘制一幅完整的地图.pdf
ArcGIS Engine开发实例教程,讲述AE开发具体实例的开发过程。
Qt结合ArcGIS Engine 开发
ArcGIS Engine 是专门用于开发 GIS 系统的开发包,目前最新版本是9.3。基于 ArcGIS Engine,结合程序开发语言可以开发具有很强专业性的GIS系统。而且所开发的系统不需要客户端安装 ArcGIS软件,只需要安装 ArcGIS ...
ArcGIS Engine 开发手册,是利用.NET + ArcGIS Engine进行Arcgis 二次开发的入门教程。
arcgis engine C# 建模 开发
开发实例,有助于arcgis engine初学者学习。
ArcGIS Engine中文开发指南清晰版,PDF版本,入门必备
ArcGIS Engine基础开发教程(5)——学习地图查询 地图查询、统计是一个GIS系统的基本的功能模块,实际上统计功能的前提也是通过查询获取结果以文字或者图表等报表的形式展现查询结果数据。 地图查询有两种类型的查询...
详细讲解了ArcGIS Engine开发中的借口查询,对ArcGIS Engine开发有一定的帮助