/// <summary> /// 创建取消操作 /// </summary> /// <returns></returns> private static ITrackCancel CreateTrackCancel() { ITrackCancel trackCancel = new CancelTrackerClass(); trackCancel.Reset(); trackCancel.CancelOnKeyPress = true; //点击ESC键时,中止转出 trackCancel.CancelOnClick = false; trackCancel.ProcessMessages = true; return(trackCancel); }
///<summary>Flash geometry on the display.</summary> ///<param name="geometry"> The input IGeometry to flash. Supported geometry types are GeometryBag, Polygon, Polyline, Point and Multipoint.</param> ///<param name="screenDisplay">An IScreenDisplay reference</param> ///<param name="delay">An integer that is the time in milliseconds to wait.</param> public static void FlashGeometry(IGeometry geometry, IScreenDisplay screenDisplay, int delay, int times) { if (geometry == null || screenDisplay == null) { return; } bool continueFlashing = true; using (ComReleaser comReleaser = new ComReleaser()) { ITrackCancel cancelTracker = new CancelTrackerClass(); comReleaser.ManageLifetime(cancelTracker); screenDisplay.CancelTracker = cancelTracker; short cacheID = screenDisplay.AddCache(); int cacheMemDC = screenDisplay.get_CacheMemDC(cacheID); IRgbColor fillColor = new RgbColorClass(); comReleaser.ManageLifetime(fillColor); fillColor.Green = 128; IRgbColor lineColor = new RgbColorClass(); comReleaser.ManageLifetime(lineColor); screenDisplay.StartDrawing(cacheMemDC, cacheID); DrawGeometry(geometry, fillColor, lineColor, (IDisplay)screenDisplay, cancelTracker); ESRI.ArcGIS.esriSystem.tagRECT RECT = new tagRECT(); screenDisplay.FinishDrawing(); for (int j = 0; j < times; j++) { if (continueFlashing == true) { screenDisplay.DrawCache(screenDisplay.hDC, cacheID, ref RECT, ref RECT); if (delay > 0) { System.Threading.Thread.Sleep(delay); screenDisplay.Invalidate(null, true, cacheID); screenDisplay.UpdateWindow(); System.Threading.Thread.Sleep(delay); } } } //--------------------------------------------------------------------- screenDisplay.RemoveCache(cacheID); cancelTracker.Reset(); } }
/// <summary> /// Exports the map extent. /// </summary> /// <param name="activeView">The active view.</param> /// <param name="outRect">The out rect.</param> /// <param name="sOutputPath">The output file path.</param> /// <param name="dResolution">The d resolution.</param> /// <returns><c>true</c> if succeed, <c>false</c> otherwise.</returns> public bool ExportMapExtent(IActiveView activeView, Size outRect, string sOutputPath, double dResolution) { bool result; try { if (activeView == null) { result = false; } else { IExport export = null; if (sOutputPath.EndsWith(".jpg")) { export = new ExportJPEGClass(); } else if (sOutputPath.EndsWith(".tif")) { export = new ExportTIFFClass(); } else if (sOutputPath.EndsWith(".bmp")) { export = new ExportBMPClass(); } else if (sOutputPath.EndsWith(".emf")) { export = new ExportEMFClass(); } else if (sOutputPath.EndsWith(".png")) { export = new ExportPNGClass(); } else if (sOutputPath.EndsWith(".gif")) { export = new ExportGIFClass(); } export.ExportFileName = sOutputPath; IEnvelope extent = activeView.Extent; export.Resolution = dResolution; tagRECT tagRECT = default(tagRECT); tagRECT.left = (tagRECT.top = 0); tagRECT.right = outRect.Width; tagRECT.bottom = (int)((double)tagRECT.right * extent.Height / extent.Width); IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords((double)tagRECT.left, (double)tagRECT.top, (double)tagRECT.right, (double)tagRECT.bottom); export.PixelBounds = envelope; ITrackCancel trackCancel = new CancelTrackerClass(); export.TrackCancel = trackCancel; trackCancel.Reset(); trackCancel.CancelOnKeyPress = true; trackCancel.CancelOnClick = false; trackCancel.ProcessMessages = true; int hDC = export.StartExporting(); activeView.Output(hDC, (int)((short)export.Resolution), ref tagRECT, extent, trackCancel); bool flag = trackCancel.Continue(); if (flag) { export.FinishExporting(); export.Cleanup(); } else { export.Cleanup(); } flag = trackCancel.Continue(); result = true; } } catch (Exception ex) { string message = ex.Message; result = false; } return(result); }
//输出当前地图至指定的文件 public static void ExportActiveView(IActiveView pView, Size outRect, string outPath) { try { //参数检查 if (pView == null) { throw new Exception("输入参数错误,无法生成图片文件!"); } //根据给定的文件扩展名,来决定生成不同类型的对象 ESRI.ArcGIS.Output.IExport export = null; if (outPath.EndsWith(".jpg", StringComparison.OrdinalIgnoreCase)) { export = new ESRI.ArcGIS.Output.ExportJPEGClass(); } else if (outPath.EndsWith(".tiff", StringComparison.OrdinalIgnoreCase)) { export = new ESRI.ArcGIS.Output.ExportTIFFClass(); } else if (outPath.EndsWith(".bmp", StringComparison.OrdinalIgnoreCase)) { export = new ESRI.ArcGIS.Output.ExportBMPClass(); } else if (outPath.EndsWith(".emf", StringComparison.OrdinalIgnoreCase)) { export = new ESRI.ArcGIS.Output.ExportEMFClass(); } else if (outPath.EndsWith(".png", StringComparison.OrdinalIgnoreCase)) { export = new ESRI.ArcGIS.Output.ExportPNGClass(); } else if (outPath.EndsWith(".gif", StringComparison.OrdinalIgnoreCase)) { export = new ESRI.ArcGIS.Output.ExportGIFClass(); } SetOutputQuality(pView, 1); export.ExportFileName = outPath; IEnvelope pEnvelope = pView.Extent; //导出参数 export.Resolution = 300; tagRECT exportRect = new tagRECT(); exportRect.left = exportRect.top = 0; exportRect.right = outRect.Width; exportRect.bottom = (int)(exportRect.right * pEnvelope.Height / pEnvelope.Width); ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass(); //输出范围 envelope.PutCoords(exportRect.left, exportRect.top, exportRect.right, exportRect.bottom); export.PixelBounds = envelope; //可用于取消操作 ITrackCancel pCancel = new CancelTrackerClass(); export.TrackCancel = pCancel; pCancel.Reset(); //点击ESC键时,中止转出 pCancel.CancelOnKeyPress = true; pCancel.CancelOnClick = false; pCancel.ProcessMessages = true; //获取handle System.Int32 hDC = export.StartExporting(); //开始转出 pView.Output(hDC, (System.Int32)export.Resolution, ref exportRect, pEnvelope, pCancel); bool bContinue = pCancel.Continue(); //捕获是否继续 if (bContinue) { export.FinishExporting(); export.Cleanup(); } else { export.Cleanup(); } bContinue = pCancel.Continue(); } catch (Exception e) { //错误信息提示 } }
/// <summary> /// 输出当前地图至指定的文件 /// </summary> /// <param name="pView"></param> /// <param name="outPath"></param> public void ExportMapExtent(IActiveView pView, string outPath) { try { //参数检查 if (pView == null) { throw new Exception("输入参数错误,无法生成图片文件!"); } //根据给定的文件扩展名,来决定生成不同类型的对象 IExport export = null; if (outPath.EndsWith(".jpg")) { export = new ExportJPEGClass(); } else if (outPath.EndsWith(".tiff")) { export = new ExportTIFFClass(); } else if (outPath.EndsWith(".bmp")) { export = new ExportBMPClass(); } else if (outPath.EndsWith(".emf")) { export = new ExportEMFClass(); } else if (outPath.EndsWith(".png")) { export = new ExportPNGClass(); } else if (outPath.EndsWith(".gif")) { export = new ExportGIFClass(); } export.ExportFileName = outPath; IEnvelope pEnvelope = pView.Extent; //导出参数 export.Resolution = 300; tagRECT exportRect = new tagRECT(); exportRect.left = 0; exportRect.top = 0; //这里暂时固定大小 exportRect.right = 700; exportRect.bottom = 1000; IEnvelope envelope = new EnvelopeClass(); //输出范围 envelope.PutCoords(exportRect.left, exportRect.bottom, exportRect.right, exportRect.top); export.PixelBounds = envelope; //可用于取消操作 ITrackCancel pCancel = new CancelTrackerClass(); export.TrackCancel = pCancel; pCancel.Reset(); //点击ESC键时,中止转出 pCancel.CancelOnKeyPress = true; pCancel.CancelOnClick = false; pCancel.ProcessMessages = true; //获取handle int hDC = export.StartExporting(); //开始转出 pView.Output(hDC, (int)export.Resolution, ref exportRect, pEnvelope, pCancel); bool bContinue = pCancel.Continue(); //捕获是否继续 if (bContinue) { export.FinishExporting(); export.Cleanup(); MessageBox.Show("导出至" + outPath); } else { export.Cleanup(); } bContinue = pCancel.Continue(); } catch (Exception excep) { MessageBox.Show("导出失败" + excep.Message);//错误信息提示 } }
/// <summary> /// 打印或者输出 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnPrint_Click(object sender, EventArgs e) { if (axPageLayoutControl1.ActiveView.FocusMap.LayerCount == 0) { MessageBox.Show("No Map !"); return; } if (rdoPrint.Checked) { printDialog1.AllowSomePages = true; //允许用户选择打印哪些页面 printDialog1.ShowHelp = true; printDialog1.Document = document; DialogResult result = printDialog1.ShowDialog(); if (result == DialogResult.OK) { document.Print(); } } if (rdoOutput.Checked) { IExport export = null; string path = outputPath.Text; if (path == "无") { MessageBox.Show("请先选择导出路径"); return; } export = getExportClass(path); if (export == null) { MessageBox.Show("导出路径错误"); return; } export.ExportFileName = path; IEnvelope pEnvelope = axPageLayoutControl1.Extent; //导出参数 export.Resolution = 300; tagRECT exportRect = new tagRECT(); exportRect.left = 0; exportRect.top = 0; //这里暂时固定大小 exportRect.right = 1000; exportRect.bottom = 1300; IEnvelope envelope = new EnvelopeClass(); //输出范围 envelope.PutCoords(exportRect.left, exportRect.bottom, exportRect.right, exportRect.top); export.PixelBounds = envelope; //可用于取消操作 ITrackCancel pCancel = new CancelTrackerClass(); export.TrackCancel = pCancel; pCancel.Reset(); //点击ESC键时,中止转出 pCancel.CancelOnKeyPress = true; pCancel.CancelOnClick = false; pCancel.ProcessMessages = true; //获取handle int hDC = export.StartExporting(); //开始转出 axPageLayoutControl1.ActiveView.Output(hDC, (int)export.Resolution, ref exportRect, pEnvelope, pCancel); bool bContinue = pCancel.Continue(); //捕获是否继续 if (bContinue) { export.FinishExporting(); export.Cleanup(); MessageBox.Show("导出至" + path); } else { export.Cleanup(); } bContinue = pCancel.Continue(); } }