I am trying to export without Arcmap so i created a webservice in C#. The export works OK. The problem is that whatever i do with the activeview(pan, zoom) it is not affected to the exported image. I always get the same image. So the ZoomInCenter() doesn't work. Please help. (Using Arcgis 9.3.1 and visual studio 2008)
public void ZoomInCenter()
{
IMapDocument ipMapDoc;
ipMapDoc = new MapDocumentClass();
ipMapDoc.Open(@"c:\temp\tryout.mxt", "");
IActiveView activeView = ipMapDoc.PageLayout as IActiveView;
activeView.Activate(GetDesktopWindow());
IEnvelope envelope = activeView.Extent;
// Get the center point of the envelope.
IPoint centerPoint = new PointClass();
centerPoint.X = ((envelope.XMax - envelope.XMin) / 2) + envelope.XMin;
centerPoint.Y = ((envelope.YMax - envelope.YMin) / 2) + envelope.YMin;
//Resize the envelope width.
envelope.Width = envelope.Width / 2;
//Resize the envelope height.
envelope.Height = envelope.Height / 2;
//Move the envelope to the center point.
envelope.CenterAt(centerPoint);
//Set the envelope to view extent.
activeView.Extent = envelope;
activeView.Refresh();
CreateJPEGFromActiveView(activeView, @"c:\temp\New.jpg");
}
public System.Boolean CreateJPEGFromActiveView(ESRI.ArcGIS.Carto.IActiveView activeView, System.String pathFileName)
{
//parameter check
if (activeView == null || !(pathFileName.EndsWith(".jpg")))
{
return false;
}
ESRI.ArcGIS.Output.IExport export = new ESRI.ArcGIS.Output.ExportJPEGClass();
export.ExportFileName = pathFileName;
// Microsoft Windows default DPI resolution
export.Resolution = 96;
ESRI.ArcGIS.Display.tagRECT exportRECT = activeView.ExportFrame;
ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
export.PixelBounds = envelope;
System.Int32 hDC = export.StartExporting();
activeView.Output(hDC, (System.Int16)export.Resolution, ref exportRECT, null, null);
// Finish writing the export file and cleanup any intermediate files
export.FinishExporting();
export.Cleanup();
return true;
}