AE二次开发C#语言导出地图为JPG、TIF、PDF图片
我的开发环境为ArcGIS Engine 10.2与Visual studio2010。创建一个菜单或按钮,创建一个点击事件,粘贴代码即可实现。我的主地图名称为axMapControl1,如果变动则需要修改(注意相关事件的添加与动态链接库的引入)!,这个导出是当前地图窗口范围的导出,导出的范围取决于地图窗口的当前内容。SaveFileDialog 的FilterIndex 从1开始不是从0,这点容易出错!
实现代码:
private void 地图导出_Click(object sender, EventArgs e)
{
ExportMapToImage();
}
private void ExportMapToImage()
{
try
{
SaveFileDialog pSaveDialog = new SaveFileDialog();
pSaveDialog.FileName = "";
pSaveDialog.Filter = "JPG图片(*.JPG)|*.jpg|tif图片(*.tif)|*.tif|PDF文档(*.PDF)|*.pdf";
if (pSaveDialog.ShowDialog() == DialogResult.OK)
{
double iScreenDispalyResolution = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.Resolution;// 获取屏幕分辨率的值
IExporter pExporter = null;
if (pSaveDialog.FilterIndex == 1)
{
pExporter = new JpegExporter() as IExporter;
}
else if (pSaveDialog.FilterIndex == 2)
{
pExporter = new TiffExporter() as IExporter;
}
else if (pSaveDialog.FilterIndex == 3)
{
pExporter = new PDFExporter() as IExporter;
}
pExporter.ExportFileName = pSaveDialog.FileName;
pExporter.Resolution = (short)iScreenDispalyResolution; //分辨率
tagRECT deviceRect = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.get_DeviceFrame();
IEnvelope pDeviceEnvelope = new Envelope() as IEnvelope;
pDeviceEnvelope.PutCoords(deviceRect.left, deviceRect.bottom, deviceRect.right, deviceRect.top);
pExporter.PixelBounds = pDeviceEnvelope; // 输出图片的范围
ITrackCancel pCancle = new CancelTracker();//可用ESC键取消操作
axMapControl1.ActiveView.Output(pExporter.StartExporting(), pExporter.Resolution, ref deviceRect, axMapControl1.ActiveView.Extent, pCancle);
Application.DoEvents();
pExporter.FinishExporting();
}
}
catch (Exception Err)
{
MessageBox.Show(Err.Message, "输出图片", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
来源:CSDN
作者:努力搬砖的giser
链接:https://blog.csdn.net/qq_41441896/article/details/103564996