/// <summary> /// IExport point to certain type of instantiation /// </summary> /// <param name="pOutPath"></param> /// <returns></returns> public static IExport OutExport(string pOutPath) { IExport outExport = null; if (pOutPath.EndsWith(".jpg")) { outExport = new ExportJPEGClass(); //Information of Corordinates, BUT also NOT WELL worked as for .png IWorldFileSettings WFS = outExport as IWorldFileSettings; WFS.OutputWorldFile = true; } else if (pOutPath.EndsWith(".tif")) { outExport = new ExportTIFFClass(); //Information of Corordinates ((IExportTIFF)outExport).GeoTiff = true; } else if (pOutPath.EndsWith(".png")) { outExport = new ExportPNGClass(); } return(outExport); }
/// <summary> /// 区域导出 /// </summary> /// <param name="pGeo">几何图形</param> /// <param name="OutputResolution">输出分辨率</param> /// <param name="ExpPath">输出路径</param> /// <param name="view">视图</param> public static void ExportRegion(IGeometry pGeo, int OutputResolution, string ExpPath, IActiveView view) { IExport export = null; IWorldFileSettings settings = null; IEnvelope envelope2 = pGeo.Envelope; string str = ExpPath.Substring(ExpPath.Length - 3, 3).ToUpper(); switch (str) { case "JPG": settings = new ExportJPEGClass(); export = new ExportJPEGClass(); settings = export as IWorldFileSettings;; settings.MapExtent = envelope2; settings.OutputWorldFile = false; break; case "BMP": settings = new ExportBMPClass(); export = new ExportBMPClass(); settings = export as IWorldFileSettings;; settings.MapExtent = envelope2; settings.OutputWorldFile = false; break; case "TIF": settings = new ExportTIFFClass(); export = new ExportTIFFClass(); settings = export as IWorldFileSettings;; settings.MapExtent = envelope2; settings.OutputWorldFile = false; break; case "PNG": settings = new ExportPNGClass(); export = new ExportPNGClass(); settings = export as IWorldFileSettings; settings.MapExtent = envelope2; settings.OutputWorldFile = false; break; default: break; } if (settings == null) { return; } export.ExportFileName = ExpPath; int num = (int)Math.Round(view.ScreenDisplay.DisplayTransformation.Resolution); tagRECT grect2 = new tagRECT(); IEnvelope envelope3 = new EnvelopeClass(); view.ScreenDisplay.DisplayTransformation.TransformRect(envelope2, ref grect2, 9); grect2.left = 0; grect2.top = 0; grect2.right = (int)Math.Round((double)((grect2.right - grect2.left) * (((double)OutputResolution) / ((double)num)))); grect2.bottom = (int)Math.Round((double)((grect2.bottom - grect2.top) * (((double)OutputResolution) / ((double)num)))); envelope3.PutCoords((double)grect2.left, (double)grect2.top, (double)grect2.right, (double)grect2.bottom); export.PixelBounds = envelope3; view.GraphicsContainer.DeleteAllElements(); view.Output(export.StartExporting(), OutputResolution, ref grect2, envelope2, null); export.FinishExporting(); export.Cleanup(); AddElement(pGeo, view); }
//Function: Export map //Date: 2019/4/3 public void ExportMap(int pOutputResolution, string pExportFileName, bool pWriteWorldFile, double pWidth, double pHeight) { IActiveView docActiveView; IExport docExport; IPrintAndExport docPrintExport; IWorldFileSettings pWorldFile = null; ESRI.ArcGIS.esriSystem.tagRECT userRECT = new ESRI.ArcGIS.esriSystem.tagRECT(); IEnvelope pEnv = new EnvelopeClass(); string pFileType; int pFileNameLength = pExportFileName.Length; if (pFileNameLength > 3) { pFileType = pExportFileName.Substring(pFileNameLength - 3, 3); } else { pFileType = pExportFileName; } switch (pFileType) { case "jpg": docExport = new ExportJPEGClass(); break; case "png": docExport = new ExportPNGClass(); break; case "tif": docExport = new ExportTIFFClass(); break; default: docExport = new ExportJPEGClass(); break; } if (miLayoutView.Checked) { docActiveView = axPageLayoutControl1.ActiveView; } else { docActiveView = axMapControl1.ActiveView; } pEnv = docActiveView.Extent; pWorldFile = (IWorldFileSettings)docExport; pWorldFile.MapExtent = pEnv; pWorldFile.OutputWorldFile = pWriteWorldFile; userRECT.left = 0; userRECT.top = 0; userRECT.right = Convert.ToInt32(pWidth); userRECT.bottom = Convert.ToInt32(pHeight); IEnvelope pDriverBounds = new EnvelopeClass(); pDriverBounds.PutCoords(userRECT.top, userRECT.bottom, userRECT.right, userRECT.top); docExport.PixelBounds = pDriverBounds; docPrintExport = new PrintAndExportClass(); docExport.ExportFileName = pExportFileName; docPrintExport.Export(docActiveView, docExport, pOutputResolution, true, null); }
private void ExportTool() { IExport pExport = null; // IExportJPEG pExportFormat; IWorldFileSettings pWorldFile = null; IExportImage pExportType; IEnvelope pEnv = new Envelope() as IEnvelope; int lResolution; lResolution = Convert.ToInt32(this.numericUpDown1.Value); switch (this.saveFileDialog1.Filter.ToString().Trim().Substring(0, 3)) { case "jpg": pExport = new ExportJPEG() as IExport; break; case "bmp": pExport = new ExportBMP() as IExport; break; case "gif": pExport = new ExportGIF() as IExport; break; case "tif": pExport = new ExportTIFF() as IExport; break; case "png": pExport = new ExportPNG() as IExport; break; case "emf": pExport = new ExportEMF() as IExport; break; case "pdf": pExport = new ExportPDF() as IExport; break; case ".ai": pExport = new ExportAI() as IExport; break; case "svg": pExport = new ExportSVG() as IExport; break; case "ps": pExport = new ExportPS() as IExport; break; default: pExport = new ExportJPEG() as IExport; break; } if (this.textBox1.Text.ToString().Trim() != "") { if (System.IO.File.Exists(this.textBox1.Text.ToString()) == true) { MessageBox.Show("该文件已经存在,请重新命名!"); this.textBox1.Text = ""; this.textBox1.Focus(); } else { pExport.ExportFileName = this.textBox1.Text; pExport.Resolution = lResolution; pExportType = pExport as IExportImage; pExportType.ImageType = esriExportImageType.esriExportImageTypeTrueColor; pEnv = pActiveView.Extent; pWorldFile = (IWorldFileSettings)pExport; pWorldFile.MapExtent = pEnv; pWorldFile.OutputWorldFile = false; tagRECT deviceRECT; deviceRECT = Form1.m_mapControl.ActiveView.ScreenDisplay.DisplayTransformation.get_DeviceFrame(); IEnvelope pDriverBounds; pDriverBounds = new Envelope() as IEnvelope; pDriverBounds.PutCoords(deviceRECT.left, deviceRECT.bottom, deviceRECT.right, deviceRECT.top); pExport.PixelBounds = pDriverBounds; ITrackCancel pTrackCancel = new TrackCancel(); Form1.m_mapControl.ActiveView.Output(pExport.StartExporting(), lResolution, ref deviceRECT, pActiveView.Extent, pTrackCancel); pExport.FinishExporting(); MessageBox.Show("打印图片保存成功!", "保存", MessageBoxButtons.OK); this.Close(); } } else { MessageBox.Show("请保存文件!"); } }
private void button2_Click(object sender, EventArgs e) { if (System.IO.File.Exists(textBoxFileName.Text.ToString()) == true) { MessageBox.Show("该文件已经存在,请重新命名!"); textBoxFileName.SelectAll(); } else { IExport pExport = null; IWorldFileSettings pWorldFile = null; IExportImage pExportType; IEnvelope pDriverBounds = null; ESRI.ArcGIS.esriSystem.tagRECT userRECT = new ESRI.ArcGIS.esriSystem.tagRECT(); IEnvelope pEnv = new EnvelopeClass(); string FilePath = this.m_strFileName; string[] strFileName = FilePath.Split('.'); string strFileType = strFileName[1]; switch (strFileType) { case "jpg": pExport = new ExportJPEGClass(); break; case "bmp": pExport = new ExportBMPClass(); break; case "gif": pExport = new ExportGIFClass(); break; case "tif": pExport = new ExportTIFFClass(); break; case "png": pExport = new ExportPNGClass(); break; case "emf": pExport = new ExportEMFClass(); break; case "pdf": pExport = new ExportPDFClass(); break; case ".ai": pExport = new ExportAIClass(); break; case "svg": pExport = new ExportSVGClass(); break; default: pExport = new ExportJPEGClass(); break; } pExport.ExportFileName = this.m_strFileName; pExport.Resolution = Convert.ToInt32(numUDresolution.Value); pExportType = pExport as IExportImage; pExportType.ImageType = esriExportImageType.esriExportImageTypeTrueColor; pEnv = m_pageLayoutControl.ActiveView.Extent; pWorldFile = (IWorldFileSettings)pExport; pWorldFile.MapExtent = pEnv; pWorldFile.OutputWorldFile = false; userRECT.top = 0; userRECT.left = 0; userRECT.right = Convert.ToInt32(txtBoxWidth.Text); userRECT.bottom = Convert.ToInt32(txtBoxHeight.Text); pDriverBounds = new EnvelopeClass(); pDriverBounds.PutCoords(userRECT.top, userRECT.bottom, userRECT.right, userRECT.top); pExport.PixelBounds = pDriverBounds; ITrackCancel pTrackCancel = new TrackCancelClass(); m_pageLayoutControl.ActiveView.Output(pExport.StartExporting(), Convert.ToInt32(numUDresolution.Value), ref userRECT, m_pageLayoutControl.ActiveView.Extent, pTrackCancel); pExport.FinishExporting(); MessageBox.Show("打印图片保存成功!", "保存", MessageBoxButtons.OK); this.Close(); } }