将地图输出成png图片
1.添加菜单
2.编写代码
private void ExportMapToImage()
{
try
{
SaveFileDialog pSaveDialog = new SaveFileDialog();
pSaveDialog.FileName = "";
pSaveDialog.Filter = "PNG图片(*.PNG)|*.PNG|JPG图片(*.JPG)|*.jpg|tif图片(*.tif)|*.tif|PDF文档(*.PDF)|*.pdf";
if (pSaveDialog.ShowDialog() == DialogResult.OK)
{
double iScreenDispalyResolution = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.Resolution;// 获取屏幕分辨率的值
IExport pExporter = null;
if (pSaveDialog.FilterIndex == 1)
{
pExporter = new ExportPNGClass();
}
else if (pSaveDialog.FilterIndex == 2)
{
pExporter = new ExportJPEGClass();
}
else if (pSaveDialog.FilterIndex == 3)
{
pExporter = new ExportPDFClass();
}
pExporter.ExportFileName = pSaveDialog.FileName;
pExporter.Resolution = (short)iScreenDispalyResolution; //分辨率
tagRECT deviceRect = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.get_DeviceFrame();
IEnvelope pDeviceEnvelope = new EnvelopeClass();
pDeviceEnvelope.PutCoords(deviceRect.left, deviceRect.bottom, deviceRect.right, deviceRect.top);
pExporter.PixelBounds = pDeviceEnvelope; // 输出图片的范围
ITrackCancel pCancle = new CancelTrackerClass();//可用ESC键取消操作
axMapControl1.ActiveView.Output(pExporter.StartExporting(), (int)pExporter.Resolution, ref deviceRect, axMapControl1.ActiveView.Extent, pCancle);
Application.DoEvents();
pExporter.FinishExporting();
}
}
catch (Exception Err)
{
MessageBox.Show(Err.Message, "输出图片", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void 输出成pngToolStripMenuItem_Click(object sender, EventArgs e)
{
ExportMapToImage();
}
3.添加引用
using ESRI.ArcGIS.Output;