//导出地图 public void ExportMapToImage(AxPageLayoutControl axPageLayoutControl1) { try { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.FileName = ""; saveFileDialog.Filter = "JPG图片(*.JPG)|*.jpg|tif图片(*.tif)|*.tif|PDF文档(*.PDF)|*.pdf"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { double iScreenDispalyResolution = axPageLayoutControl1.ActiveView.ScreenDisplay. DisplayTransformation.Resolution;// 获取屏幕分辨率的值 IExporter exporter = new JpegExporterClass(); exporter.ExportFileName = saveFileDialog.FileName; exporter.Resolution = (short)iScreenDispalyResolution; //分辨率 tagRECT deviceRect = axPageLayoutControl1.ActiveView.ScreenDisplay.DisplayTransformation.get_DeviceFrame(); IEnvelope deviceEnvelope = new EnvelopeClass(); deviceEnvelope.PutCoords(deviceRect.left, deviceRect.bottom, deviceRect.right, deviceRect.top); exporter.PixelBounds = deviceEnvelope; // 输出图片的范围 ITrackCancel pCancle = new CancelTrackerClass(); //可用ESC键取消操作 axPageLayoutControl1.ActiveView.Output(exporter.StartExporting(), exporter.Resolution, ref deviceRect, axPageLayoutControl1.ActiveView.Extent, pCancle); Application.DoEvents(); exporter.FinishExporting(); } } catch (Exception Err) { MessageBox.Show(Err.Message, "输出图片", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public static void ExportActiveView(IActiveView pActiveView, string strImagePath) { IExporter pExporter; IEnvelope pEnv; tagRECT rectExpFrame; int hdc; short dpi; pExporter = new JpegExporterClass(); pEnv = new EnvelopeClass(); //Setup the exporter rectExpFrame = pActiveView.ExportFrame; pEnv.PutCoords(rectExpFrame.left, rectExpFrame.top, rectExpFrame.right, rectExpFrame.bottom); dpi = 96; pExporter.PixelBounds = pEnv; pExporter.ExportFileName = strImagePath; pExporter.Resolution = dpi; hdc = pExporter.StartExporting(); pActiveView.Output(hdc, dpi, ref rectExpFrame, null, null); pExporter.FinishExporting(); }
public static void ExportMap(IActiveView activeView) { SaveFileDialog sfg = new SaveFileDialog() { Title = "导出jpg格式图片", Filter = "JPG图片(*.jpg)|*.jpg" }; if (sfg.ShowDialog() == DialogResult.OK) { // 打印机接口 IExporter pExporter = new JpegExporterClass() { ExportFileName = sfg.FileName, Resolution = (short)activeView.ScreenDisplay.DisplayTransformation.Resolution }; // 设置输出地图范围 tagRECT pTagRECT = activeView.ScreenDisplay.DisplayTransformation.get_DeviceFrame(); IEnvelope pEnvelope = new EnvelopeClass() { XMin = pTagRECT.left, XMax = pTagRECT.right, YMin = pTagRECT.bottom, YMax = pTagRECT.top }; pExporter.PixelBounds = pEnvelope; //// 输出地图 activeView.Output(pExporter.StartExporting(), pExporter.Resolution, ref pTagRECT, activeView.Extent, null); Application.DoEvents(); pExporter.FinishExporting(); MessageBox.Show("已将地图导出为jpg格式图片"); } }
public bool ExportImage(IActiveView pActiveView, ref string sFileName, ref int iImageWidth, ref int iImageHeight, double dDpi, bool bOverwritePrompt) { try { if (pActiveView == null) { return(false); } if (string.IsNullOrEmpty(sFileName)) { sFileName = GISFunFactory.SystemFun.GetTempPath() + "~ExportImage.Jpg"; bOverwritePrompt = false; } if ((File.Exists(sFileName) & bOverwritePrompt) && (Interaction.MsgBox("文件 " + sFileName + " 已存在。\r\n是否要替换?", MsgBoxStyle.YesNo, "确认替换") != MsgBoxResult.Yes)) { return(false); } if (File.Exists(sFileName)) { FileSystem.Kill(sFileName); } if (File.Exists(sFileName)) { Interaction.MsgBox("文件 " + sFileName + " 无法删除。\r\n共享冲突,文件正在使用。", MsgBoxStyle.Exclamation, "删除文件错误"); return(false); } double resolution = 0.0; IDisplayTransformation displayTransformation = null; displayTransformation = pActiveView.ScreenDisplay.DisplayTransformation; if (displayTransformation.ZoomResolution) { displayTransformation.ZoomResolution = false; resolution = displayTransformation.Resolution; displayTransformation.ZoomResolution = true; } else { resolution = displayTransformation.Resolution; } if (resolution <= 0.0) { resolution = 96.0; } if (dDpi <= 0.0) { dDpi = resolution; } tagRECT pixelBounds = new tagRECT(); pixelBounds = pActiveView.ExportFrame; pixelBounds.bottom = (int)(double.Parse(pixelBounds.bottom.ToString()) * (dDpi / resolution)); pixelBounds.right = (int)(double.Parse(pixelBounds.right.ToString()) * (dDpi / resolution)); if (iImageWidth > 0) { dDpi *= (double)(iImageWidth / pixelBounds.right); pixelBounds.bottom *= iImageWidth / pixelBounds.right; pixelBounds.right = iImageWidth; } if ((iImageHeight > 0) & (pixelBounds.bottom > iImageHeight)) { dDpi *= (double)(iImageHeight / pixelBounds.bottom); pixelBounds.right *= iImageHeight / pixelBounds.bottom; pixelBounds.bottom = iImageHeight; } IExporter exporter = null; exporter = new JpegExporterClass(); if (exporter == null) { return(false); } exporter.Resolution = (short)dDpi; exporter.ExportFileName = sFileName; IEnvelope envelope = null; envelope = new EnvelopeClass(); envelope.PutCoords((double)pixelBounds.left, (double)pixelBounds.bottom, (double)pixelBounds.right, (double)pixelBounds.top); exporter.PixelBounds = envelope; int hDC = 0; hDC = exporter.StartExporting(); pActiveView.Output(hDC, (int)dDpi, ref pixelBounds, null, null); exporter.FinishExporting(); iImageWidth = (int)envelope.Width; iImageHeight = (int)envelope.Height; return(true); } catch (Exception exception) { this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.CoreFun", "ExportImage", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", ""); return(false); } }
public static void ExportActiveView(IActiveView pActiveView ,string strImagePath) { IExporter pExporter; IEnvelope pEnv; tagRECT rectExpFrame; int hdc; short dpi; pExporter=new JpegExporterClass(); pEnv=new EnvelopeClass(); //Setup the exporter rectExpFrame = pActiveView.ExportFrame; pEnv.PutCoords(rectExpFrame.left,rectExpFrame.top,rectExpFrame.right,rectExpFrame.bottom); dpi=96; pExporter.PixelBounds=pEnv; pExporter.ExportFileName=strImagePath; pExporter.Resolution=dpi; hdc=pExporter.StartExporting(); pActiveView.Output(hdc,dpi,ref rectExpFrame,null,null); pExporter.FinishExporting(); }