public static void ExportMapEx(string filepath, int resolution, AxMapControl curMapControl)
{
try
{
// 从Style文件中获取指定的指北针
string stylefilePath = Application.StartupPath + @"\style\testArrow.ServerStyle";
INorthArrow pNorthArrow = GetSymbol(stylefilePath, "North Arrows", "ESRI North 2") as INorthArrow;
if (pNorthArrow == null) return;
// 设置指北针的位置及大小
ESRI.ArcGIS.Geometry.IEnvelope envelope3 = new ESRI.ArcGIS.Geometry.EnvelopeClass();
envelope3.PutCoords(2, 2, 5, 5);
// 设置当前活动视图,m_MapDocument为当前打开的地图文档
IActiveView pCurActiveView = MyGIS.Forms.MainForm.m_MapDocument.PageLayout as IActiveView;
MyGIS.Forms.MainForm.m_MapDocument.SetActiveView(pCurActiveView);
IGraphicsContainer pGraphicContainer = (IGraphicsContainer)MyGIS.Forms.MainForm.m_MapDocument.PageLayout;
IMapFrame mapFrame = pGraphicContainer.FindFrame(pCurActiveView.FocusMap) as IMapFrame ;
IMapSurroundFrame mapSurroundFrame = new MapSurroundFrameClass();
mapSurroundFrame.MapFrame = mapFrame;
mapSurroundFrame.MapSurround = pNorthArrow as IMapSurround;
IElement element = (IElement)mapSurroundFrame;
element.Geometry = envelope3;
// 添加元素
element.Activate(pCurActiveView.ScreenDisplay);
pGraphicContainer.AddElement(element, 0);
//pCurActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, mapSurroundFrame, null);
// 这里分辨率分两种情况:96dpi和300dpi
string extension = System.IO.Path.GetExtension(filepath);
IExport pExporter = null;
if (extension == ".bmp")
{
pExporter = new ExportBMPClass();
}
else if (extension == ".jpg")
{
pExporter = new ExportJPEGClass();
}
else if (extension == ".png")
{