保存为栅格图片-MapControl截图——保存ActiveView为jpg图片

 1 ///<summary>Creates a .jpg (JPEG) file from IActiveView. Default values of 96 DPI are used for the image creation.</summary>
 2 ///
 3 ///<param name="activeView">An IActiveView interface</param>
 4 ///<param name="pathFileName">A System.String that the path and filename of the JPEG you want to create. Example: "C:\temp\test.jpg"</param>
 5 /// 
 6 ///<returns>A System.Boolean indicating the success</returns>
 7 /// 
 8 ///<remarks></remarks>
 9 public System.Boolean CreateJPEGFromActiveView(ESRI.ArcGIS.Carto.IActiveView activeView, System.String pathFileName)
10 {
11   //parameter check
12   if (activeView == null || !(pathFileName.EndsWith(".jpg")))
13   {
14     return false;
15   }
16   ESRI.ArcGIS.Output.IExport export = new ESRI.ArcGIS.Output.ExportJPEGClass();
17   export.ExportFileName = pathFileName;
18 
19   // Microsoft Windows default DPI resolution
20   export.Resolution = 96;
21   ESRI.ArcGIS.Display.tagRECT exportRECT = activeView.ExportFrame;
22   ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
23   envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
24   export.PixelBounds = envelope;
25   System.Int32 hDC = export.StartExporting();
26   activeView.Output(hDC, (System.Int16)export.Resolution, ref exportRECT, null, null);
27 
28   // Finish writing the export file and cleanup any intermediate files
29   export.FinishExporting();
30   export.Cleanup();
31 
32   return true;
33 }

 

源:http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/Create_JPEG_from_ActiveView_Snippet/004900000064000000/

 

posted @ 2016-09-06 09:15  道义相勖  Views(741)  Comments(0Edit  收藏  举报