/// <summary> /// 导出图片 /// </summary> public void ExportPictureMyself(string fileName) { IActiveView pActiveView = pagelayout.ActiveView; IEnvelope pEnv; int iOutputResolution = 600; int iScreenResolution = 96; int hDC; tagRECT exportRECT; exportRECT.left = 0; exportRECT.top = 0; exportRECT.right = pActiveView.ExportFrame.right * (iOutputResolution / iScreenResolution); exportRECT.bottom = pActiveView.ExportFrame.bottom * (iOutputResolution / iScreenResolution); pEnv = new EnvelopeClass(); pEnv.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom); IExportFileDialog pExportFileDialog = new ExportFileDialogClass(); string filename = fileName; IExport pExport = new ExportJPEGClass(); pExport.ExportFileName = filename; pExport.Resolution = iOutputResolution; pExport.PixelBounds = pEnv; hDC = pExport.StartExporting(); pActiveView.Output(hDC, (int)pExport.Resolution, ref exportRECT, null, null); pExport.FinishExporting(); pExport.Cleanup(); }
/// <summary> /// 全域导出 /// </summary> /// <param name="OutputResolution">输出分辨率</param> /// <param name="ExpPath">输出路径</param> /// <param name="view">视图</param> public static void ExportActiveView(int OutputResolution, string ExpPath, IActiveView view) { IExport pExport = null; tagRECT exportRect; IEnvelope envelope2 = view.Extent; int num = (int)Math.Round(view.ScreenDisplay.DisplayTransformation.Resolution); string sType = System.IO.Path.GetExtension(ExpPath); switch (sType) { 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 ".pdf": pExport = new ExportPDFClass(); break; default: MessageBox.Show("没有输出格式,默认到JPEG格式"); pExport = new ExportJPEGClass(); break; } pExport.ExportFileName = ExpPath; exportRect.left = 0; exportRect.top = 0; exportRect.right = (int)Math.Round((double)(view.ExportFrame.right * (((double)OutputResolution) / ((double)num)))); exportRect.bottom = (int)Math.Round((double)(view.ExportFrame.bottom * (((double)OutputResolution) / ((double)num)))); IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords((double)exportRect.left, (double)exportRect.top, (double)exportRect.right, (double)exportRect.bottom); pExport.PixelBounds = envelope; view.Output(pExport.StartExporting(), OutputResolution, ref exportRect, envelope2, null); pExport.FinishExporting(); pExport.Cleanup(); }
public void screenShot(IEnvelope IN_Envelope, string IN_SaveFile, AxMapControl IN_Axmapcontrols, double ratio) { /* * IN_Envelope为输出范围,单位为米 * IN_SaveFile为输出文件名 * IN_Axmapcontrols map控件 * ratio 影像空间分辨率的倒数 * */ if (IN_Envelope == null) { IN_Envelope = IN_Axmapcontrols.ActiveView.Extent; } IExport Temp_Exporter = new ExportJPEGClass(); //定义输出设备 Temp_Exporter IActiveView Temp_CurrentActiveView = IN_Axmapcontrols.ActiveView; tagRECT Temp_TtagRECT; //定义的是输出设备的像素大小 Temp_TtagRECT.left = 0; Temp_TtagRECT.top = 0; Temp_TtagRECT.right = (int)(IN_Envelope.Width * ratio); Temp_TtagRECT.bottom = (int)(IN_Envelope.Height * ratio); int Temp_DPI = 300; //DPI 设置 IEnvelope Temp_Envelope = new EnvelopeClass(); //定义一个Envelope来确定设备单元中输出的图片大小 Temp_Envelope.PutCoords(Temp_TtagRECT.left, Temp_TtagRECT.top, Temp_TtagRECT.right, Temp_TtagRECT.bottom); //Temp_Envelope.PutCoords(0, 0, 500, 500); 此参数只会显示图片左上角500*500区域 Temp_Exporter.Resolution = Temp_DPI; Temp_Exporter.ExportFileName = IN_SaveFile; Temp_Exporter.PixelBounds = Temp_Envelope; //IOutputRasterSettings pOutputRasterS = (IOutputRasterSettings)IN_Axmapcontrols.ActiveView.ScreenDisplay.DisplayTransformation; IOutputRasterSettings pOutputRasterS = (IOutputRasterSettings)Temp_CurrentActiveView.ScreenDisplay.DisplayTransformation; pOutputRasterS.ResampleRatio = 1; //设置了这个采样比例后,输出图片的像素和原始影像的像素一样! Temp_CurrentActiveView.Output(Temp_Exporter.StartExporting(), (int)Temp_DPI, ref Temp_TtagRECT, IN_Envelope, null); Temp_Exporter.FinishExporting(); Temp_Exporter.Cleanup(); System.Runtime.InteropServices.Marshal.ReleaseComObject(Temp_Exporter); }
public static bool OutputJPEGHiResolution(IActiveView activeView, string pathFileName) { //parameter check if (activeView == null || !(pathFileName.EndsWith(".jpg"))) { return(false); } IExport export = new ExportJPEGClass(); export.ExportFileName = pathFileName; // Because we are exporting to a resolution that differs from screen // resolution, we should assign the two values to variables for use // in our sizing calculations System.Int32 screenResolution = 96; System.Int32 outputResolution = 300; export.Resolution = outputResolution; tagRECT exportRECT; // This is a structure exportRECT.left = 0; exportRECT.top = 0; exportRECT.right = activeView.ExportFrame.right * (outputResolution / screenResolution); exportRECT.bottom = activeView.ExportFrame.bottom * (outputResolution / screenResolution); // Set up the PixelBounds envelope to match the exportRECT IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom); export.PixelBounds = envelope; int hDC = export.StartExporting(); activeView.Output(hDC, (System.Int16)export.Resolution, ref exportRECT, null, null); // Explicit Cast and 'ref' keyword needed export.FinishExporting(); export.Cleanup(); return(true); }
public static void ExportView(IActiveView view, IGeometry pGeo, int OutputResolution, int Width, int Height, string ExpPath, bool bRegion) { IExport pExport = null; tagRECT exportRect = new tagRECT(); IEnvelope pEnvelope = pGeo.Envelope; string sType = System.IO.Path.GetExtension(ExpPath); switch (sType) { 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 ".pdf": pExport = new ExportPDFClass(); break; default: MessageBox.Show("没有输出格式,默认到JPEG格式"); pExport = new ExportJPEGClass(); break; } pExport.ExportFileName = ExpPath; exportRect.left = 0; exportRect.top = 0; exportRect.right = Width; exportRect.bottom = Height;//bottom 写成 left 两天才排出错误 2016年4月17日20:24:13 if (bRegion) { view.GraphicsContainer.DeleteAllElements(); view.Refresh(); } IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords((double)exportRect.left, (double)exportRect.top, (double)exportRect.right, (double)exportRect.bottom); pExport.PixelBounds = envelope; //MessageBox.Show("Go Here! OutputResolution " + OutputResolution, "yahooo"); view.Output(pExport.StartExporting(), OutputResolution, ref exportRect, pEnvelope, null);//无法运行2016年4月17日14:42:25 /* * 当时发现错误出现在上句,对分辨率参数做了排查,但是忽略了其它参数,而最终的问题就在于其中的pEnvelope参数 * 这次能够排出错误,是因为对照了原来的代码,而在自己写程序时没有参考代码,仅靠对照排错是不够的, * 因此,要逐步缩小出错的代码块,对每一个参数都要进行检验。(2016年4月17日20:31:12) */ pExport.FinishExporting(); pExport.Cleanup(); }
/// <summary> /// Create Bitmap From ESRI Dataset /// </summary> /// <param name="dataset">Dataset to generate an image from</param> /// <param name="imageFormat">Output image format</param> /// <param name="size">Size of output image</param> /// <param name="resolution">Resolution of output image (dpi)</param> /// <param name="background">Background color</param> /// <param name="filename">Ouput filename</param> public static void CreateBitmap(IDataset dataset, esriImageFormat imageFormat, Size size, ushort resolution, Color background, string filename) { ILayer layer = null; switch (dataset.Type) { case esriDatasetType.esriDTFeatureClass: IFeatureClass featureClass = (IFeatureClass)dataset; switch (featureClass.FeatureType) { case esriFeatureType.esriFTDimension: layer = new DimensionLayerClass(); break; case esriFeatureType.esriFTAnnotation: layer = new FeatureLayerClass(); IGeoFeatureLayer geoFeaureLayer = (IGeoFeatureLayer)layer; geoFeaureLayer.DisplayAnnotation = true; break; case esriFeatureType.esriFTComplexEdge: case esriFeatureType.esriFTComplexJunction: case esriFeatureType.esriFTSimple: case esriFeatureType.esriFTSimpleEdge: case esriFeatureType.esriFTSimpleJunction: layer = new FeatureLayerClass(); break; } if (layer == null) { return; } IFeatureLayer featureLayer = (IFeatureLayer)layer; featureLayer.FeatureClass = featureClass; break; case esriDatasetType.esriDTRasterDataset: layer = new RasterLayerClass(); IRasterLayer rasterLayer = (IRasterLayer)layer; rasterLayer.CreateFromDataset((IRasterDataset)dataset); break; default: string message = string.Format("[{0}] is not supported", dataset.Type.ToString()); throw new Exception(message); } if (layer == null) { return; } // Create In-memory Map IMap map = new MapClass(); map.AddLayer(layer); IActiveView activeView = (IActiveView)map; IExport export = null; tagRECT rect = new tagRECT(); // Set Format Specific Properties switch (imageFormat) { case esriImageFormat.esriImageJPG: export = new ExportJPEGClass(); IExportJPEG exportJpeg = (IExportJPEG)export; exportJpeg.ProgressiveMode = false; exportJpeg.Quality = 100; break; default: throw new Exception("[" + imageFormat.ToString() + "] is not supported"); } if (export == null) { throw new Exception("Failed to Created Exporter"); } // Set Background if ((export is IExportBMP) || (export is IExportGIF) || (export is IExportJPEG) || (export is IExportPNG) || (export is IExportTIFF)) { IExportImage exportImage = (IExportImage)export; exportImage.ImageType = esriExportImageType.esriExportImageTypeTrueColor; exportImage.BackgroundColor = GeodatabaseUtility.ToESRIColor(background); } // Set Export Frame rect = activeView.ExportFrame; rect.left = 0; rect.top = 0; rect.right = size.Width; rect.bottom = size.Height; // Set Output Extent IEnvelope envelope = new EnvelopeClass(); envelope.PutCoords(rect.left, rect.top, rect.right, rect.bottom); export.PixelBounds = envelope; export.Resolution = resolution; export.ExportFileName = filename; // Export map to image int intHdc = export.StartExporting(); activeView.Output(intHdc, resolution, ref rect, null, null); export.FinishExporting(); export.Cleanup(); // Clear Layers map.ClearLayers(); // Release COM Objects GeodatabaseUtility.ReleaseComObject(layer); GeodatabaseUtility.ReleaseComObject(envelope); GeodatabaseUtility.ReleaseComObject(map); GeodatabaseUtility.ReleaseComObject(activeView); GeodatabaseUtility.ReleaseComObject(export); GC.Collect(); GC.WaitForPendingFinalizers(); }
/// <summary> /// 导出图片 /// </summary> public void ExportPicture(string strdefaultfilename) { if (strdefaultfilename.Contains("制")) { strdefaultfilename = strdefaultfilename.Replace("制",""); } try { IActiveView pActiveView =axPageLayoutControl1.ActiveView; IEnvelope pEnv; int iOutputResolution = 600; int iScreenResolution = 96; int hDC; tagRECT exportRECT; exportRECT.left = 0; exportRECT.top = 0; //exportRECT.right = pActiveView.ExportFrame.right; //exportRECT.bottom = pActiveView.ExportFrame.bottom; exportRECT.right = pActiveView.ExportFrame.right * (iOutputResolution / iScreenResolution); exportRECT.bottom = pActiveView.ExportFrame.bottom * (iOutputResolution / iScreenResolution); pEnv = new EnvelopeClass(); pEnv.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom); IExportFileDialog pExportFileDialog = new ExportFileDialogClass(); pExportFileDialog.DocumentName = strdefaultfilename; //bool bl; //bl = pExportFileDialog.DoModal(pEnv, pActiveView.Extent, pActiveView.Extent, 900); //if (!bl) return; //IExport pExport = pExportFileDialog.Export; //pExport.Resolution = iOutputResolution; //pExport.PixelBounds = pEnv; string filename = Application.StartupPath + @"\Image\1.jpg"; if (File.Exists(filename)) { File.Delete(filename); } IExport pExport = new ExportJPEGClass(); pExport.ExportFileName = filename; pExport.Resolution = iOutputResolution; pExport.PixelBounds = pEnv; hDC = pExport.StartExporting(); pActiveView.Output(hDC, (int)pExport.Resolution, ref exportRECT, null, null); pExport.FinishExporting(); pExport.Cleanup(); hDC = pExport.StartExporting(); pActiveView.Output(hDC, (int)pExport.Resolution, ref exportRECT, null, null); pExport.FinishExporting(); pExport.Cleanup(); // MessageBox.Show("保存成功", "提示"); } catch (Exception ax) { MessageBox.Show(ax.ToString()); } //try //{ // System.Windows.Forms.SaveFileDialog sfd = new SaveFileDialog(); // sfd.Filter = "*.jpeg|*.jpeg|*.pdf|*.pdf|*.bmp|*.bmp"; // if (sfd.ShowDialog() == DialogResult.OK) // { // IExport pExport = null; // if (1 == sfd.FilterIndex) // { // pExport = new ExportJPEGClass(); // } // else if (2 == sfd.FilterIndex) // { // pExport = new ExportPDFClass(); // } // else if (3 == sfd.FilterIndex) // { // pExport = new ExportBMPClass(); // } // pExport.ExportFileName = sfd.FileName; // //设置参数 // //默认精度 // int reslution = 300; // pExport.Resolution = reslution; // //获取导出范围 // tagRECT exportRECT = axPageLayoutControl1.ActiveView.ExportFrame; // //tagRECT exportRECT = axMapMain.ActiveView.ExportFrame; // IEnvelope pPixelBoundsEnv = new EnvelopeClass(); // pPixelBoundsEnv.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom); // pExport.PixelBounds = pPixelBoundsEnv; // //开始导出,获取DC // int hDC = pExport.StartExporting(); // IEnvelope pVisbounds = null; // ITrackCancel ptrac = null; // //导出 // axPageLayoutControl1.ActiveView.Output(hDC, (int)pExport.Resolution, ref exportRECT, pVisbounds, ptrac); // //结束导出 // pExport.FinishExporting(); // //清理导出类 // pExport.Cleanup(); // MessageBox.Show("导出成功","提示"); // } //} //catch //{ //} }
/// <summary> /// 根据Mxd输出JPG图片 /// </summary> /// <param name="pActiveView"></param> /// <param name="Resolution">分辨率</param> /// <param name="strFilePath">保存图片路径</param> /// <param name="strMxdPath">Mxd文档路径</param> private void ExportJPG(IActiveView pActiveView, int Resolution, string strFilePath, string strMxdPath) { long iPrevOutputImageQuality; IOutputRasterSettings docOutputRasterSettings; IDisplayTransformation docDisplayTransformation; tagRECT DisplayBounds; IPageLayout docPageLayout; IEnvelope docGraphicsExtentEnv; IEnvelope docMapExtEnv; IUnitConverter pUnitConvertor; IEnvelope PixelBoundsEnv; IExport pExport = new ExportJPEGClass(); try { string strPath = strFilePath + "\\" + System.IO.Path.GetFileNameWithoutExtension(strMxdPath) + ".jpg"; pExport.ExportFileName = strPath; if (System.IO.File.Exists(strPath)) { System.IO.File.Delete(strPath); } int iOutputResolution = Resolution; pExport.Resolution = iOutputResolution; docOutputRasterSettings = pActiveView.ScreenDisplay.DisplayTransformation as IOutputRasterSettings; iPrevOutputImageQuality = docOutputRasterSettings.ResampleRatio; SetOutputQuality(pActiveView, 1); if (pActiveView is IPageLayout) { DisplayBounds = pActiveView.ExportFrame; docGraphicsExtentEnv = GetGraphicsExtent(pActiveView); } else { docDisplayTransformation = pActiveView.ScreenDisplay.DisplayTransformation; DisplayBounds = docDisplayTransformation.get_DeviceFrame(); } tagRECT exportRECT; PixelBoundsEnv = new Envelope() as IEnvelope; double tempratio = iOutputResolution / Resolution; double tempbottom = DisplayBounds.bottom * tempratio; double tempright = DisplayBounds.right * tempratio; exportRECT.bottom = (int)Math.Truncate(tempbottom); exportRECT.left = 0; exportRECT.top = 0; exportRECT.right = (int)Math.Truncate(tempright); PixelBoundsEnv.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom); docMapExtEnv = null; pExport.PixelBounds = PixelBoundsEnv; int hDc = pExport.StartExporting(); pActiveView.Output(hDc, (int)pExport.Resolution, ref exportRECT, docMapExtEnv, null); pExport.FinishExporting(); } catch { } finally { //完成输出后清理临时文件 pExport.Cleanup(); docMapExtEnv = null; PixelBoundsEnv = null; docGraphicsExtentEnv = null; } }
private void OutputMap(string mxdPath, string saveMxdPath) { try { if (txtResolution.Text.Trim() == "" && cbxExpention.Text.Trim() == "") { MessageBox.Show("保存类型和分辨率不能为空!"); return; } // string fpath; IActiveView pActiveView; IExport pExport; IEnvelope pPixelBoundsEnv; int iOutputResolution; int iScreenResolution; int hDC; IMxdContents pMxdC; IMapDocument pMapDocument = new MapDocumentClass(); pMapDocument.Open(mxdPath, ""); pMxdC = pMapDocument.PageLayout as IMxdContents; // IMap pMap = pMxdC.ActiveView.FocusMap; //this.axPageLayoutControl1.ActiveView.FocusMap; // IPageLayout pPageLayout = pMxdC.PageLayout;//this.axPageLayoutControl1.PageLayout; // AxPageLayoutControl pPageLayoutControl = pMapDocument as AxPageLayoutControl; pActiveView = pMapDocument.ActiveView; pExport = new ExportJPEGClass(); // SaveFileDialog saveFileDialog1 = new SaveFileDialog(); // saveFileDialog1.InitialDirectory = Application.StartupPath; // saveFileDialog1.Filter =string.Format("{0} files (*.{0})|*.{0}",cbxExpention.Text.Trim()); string fpath = saveMxdPath + "." + cbxExpention.Text.Trim(); //if (saveFileDialog1.ShowDialog() == DialogResult.OK) //{ // fpath = saveFileDialog1.FileName.Trim(); pExport.ExportFileName = fpath; iScreenResolution = 96; iOutputResolution = 300; pExport.Resolution = iOutputResolution; tagRECT pExportFrame; pExportFrame = pActiveView.ExportFrame; tagRECT exportRECT; exportRECT.left = 0; exportRECT.top = 0; exportRECT.right = pActiveView.ExportFrame.right * (iOutputResolution / iScreenResolution); exportRECT.bottom = pActiveView.ExportFrame.bottom * (iOutputResolution / iScreenResolution); pPixelBoundsEnv = new EnvelopeClass(); pPixelBoundsEnv.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom); pExport.PixelBounds = pPixelBoundsEnv; hDC = pExport.StartExporting(); pActiveView.Output(hDC, (int)pExport.Resolution, ref exportRECT, null, null); pExport.FinishExporting(); pExport.Cleanup(); // } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void toolStripButton10_Click(object sender, EventArgs e) { try { SaveFileDialog exportJPGDialog = new SaveFileDialog(); exportJPGDialog.Title = "导出JPEG图像"; exportJPGDialog.Filter = "Jpeg Files(*.jpg,*.jpeg)|*.jpg,*.jpeg"; exportJPGDialog.RestoreDirectory = true; exportJPGDialog.ValidateNames = true; exportJPGDialog.OverwritePrompt = true; exportJPGDialog.DefaultExt = "jpg"; if (exportJPGDialog.ShowDialog() == DialogResult.OK) { double lScreenResolution; lScreenResolution = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.Resolution; IExport pExporter = new ExportJPEGClass() as IExport; //IExport pExporter = new ExportPDFClass() as IExport;//直接可以用!! pExporter.ExportFileName = exportJPGDialog.FileName; pExporter.Resolution = lScreenResolution; tagRECT deviceRECT; //用这句的话执行到底下的output()时就会出现错误:Not enough memory to create requested bitmap //axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.set_DeviceFrame(ref deviceRECT); deviceRECT = axMapControl1.ActiveView.ExportFrame; IEnvelope pDriverBounds = new EnvelopeClass(); //pDriverBounds = axMapControl1.ActiveView.FullExtent; pDriverBounds.PutCoords(deviceRECT.left, deviceRECT.bottom, deviceRECT.right, deviceRECT.top); pExporter.PixelBounds = pDriverBounds; ITrackCancel pCancel = new CancelTrackerClass(); axMapControl1.ActiveView.Output(pExporter.StartExporting(), (int)lScreenResolution, ref deviceRECT, axMapControl1.ActiveView.Extent, pCancel); pExporter.FinishExporting(); pExporter.Cleanup(); MessageBox.Show("图像保存在" + exportJPGDialog.FileName, "保存成功", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message); return; } }
/// <summary> /// 导出图片 /// </summary> public void ExportPicture(string strdefaultfilename) { if (strdefaultfilename.Contains("制")) { strdefaultfilename = strdefaultfilename.Replace("制", ""); } try { IActiveView pActiveView = axPageLayoutControl1.ActiveView; IEnvelope pEnv; int iOutputResolution = 600; int iScreenResolution = 96; int hDC; tagRECT exportRECT; exportRECT.left = 0; exportRECT.top = 0; //exportRECT.right = pActiveView.ExportFrame.right; //exportRECT.bottom = pActiveView.ExportFrame.bottom; exportRECT.right = pActiveView.ExportFrame.right * (iOutputResolution / iScreenResolution); exportRECT.bottom = pActiveView.ExportFrame.bottom * (iOutputResolution / iScreenResolution); pEnv = new EnvelopeClass(); pEnv.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom); IExportFileDialog pExportFileDialog = new ExportFileDialogClass(); pExportFileDialog.DocumentName = strdefaultfilename; //bool bl; //bl = pExportFileDialog.DoModal(pEnv, pActiveView.Extent, pActiveView.Extent, 900); //if (!bl) return; //IExport pExport = pExportFileDialog.Export; //pExport.Resolution = iOutputResolution; //pExport.PixelBounds = pEnv; string filename = Application.StartupPath + @"\Image\1.jpg"; if (File.Exists(filename)) { File.Delete(filename); } IExport pExport = new ExportJPEGClass(); pExport.ExportFileName = filename; pExport.Resolution = iOutputResolution; pExport.PixelBounds = pEnv; hDC = pExport.StartExporting(); pActiveView.Output(hDC, (int)pExport.Resolution, ref exportRECT, null, null); pExport.FinishExporting(); pExport.Cleanup(); hDC = pExport.StartExporting(); pActiveView.Output(hDC, (int)pExport.Resolution, ref exportRECT, null, null); pExport.FinishExporting(); pExport.Cleanup(); // MessageBox.Show("保存成功", "提示"); } catch (Exception ax) { MessageBox.Show(ax.ToString()); } //try //{ // System.Windows.Forms.SaveFileDialog sfd = new SaveFileDialog(); // sfd.Filter = "*.jpeg|*.jpeg|*.pdf|*.pdf|*.bmp|*.bmp"; // if (sfd.ShowDialog() == DialogResult.OK) // { // IExport pExport = null; // if (1 == sfd.FilterIndex) // { // pExport = new ExportJPEGClass(); // } // else if (2 == sfd.FilterIndex) // { // pExport = new ExportPDFClass(); // } // else if (3 == sfd.FilterIndex) // { // pExport = new ExportBMPClass(); // } // pExport.ExportFileName = sfd.FileName; // //设置参数 // //默认精度 // int reslution = 300; // pExport.Resolution = reslution; // //获取导出范围 // tagRECT exportRECT = axPageLayoutControl1.ActiveView.ExportFrame; // //tagRECT exportRECT = axMapMain.ActiveView.ExportFrame; // IEnvelope pPixelBoundsEnv = new EnvelopeClass(); // pPixelBoundsEnv.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom); // pExport.PixelBounds = pPixelBoundsEnv; // //开始导出,获取DC // int hDC = pExport.StartExporting(); // IEnvelope pVisbounds = null; // ITrackCancel ptrac = null; // //导出 // axPageLayoutControl1.ActiveView.Output(hDC, (int)pExport.Resolution, ref exportRECT, pVisbounds, ptrac); // //结束导出 // pExport.FinishExporting(); // //清理导出类 // pExport.Cleanup(); // MessageBox.Show("导出成功","提示"); // } //} //catch //{ //} }
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(); } }