Ejemplo n.º 1
0
        public static void exportMaptoJPEG(AxPageLayoutControl axPageLayoutControl)
        {
            SaveFileDialog saveDialog = new SaveFileDialog();

            saveDialog.Title    = "保存图像";
            saveDialog.FileName = "output";
            saveDialog.Filter   = "JGP图片(*.jpg)|*.jpg";
            if (saveDialog.ShowDialog() == DialogResult.OK)
            {
                double resolution =
                    axPageLayoutControl.ActiveView.ScreenDisplay.DisplayTransformation.Resolution;
                IExport pExport = new ExportJPEGClass();
                pExport.ExportFileName = saveDialog.FileName;
                pExport.Resolution     = resolution;
                tagRECT deviceRect =
                    axPageLayoutControl.ActiveView.ScreenDisplay.DisplayTransformation.get_DeviceFrame();
                IEnvelope pDeviceEnvelope = new EnvelopeClass();
                pDeviceEnvelope.PutCoords(deviceRect.left, deviceRect.bottom,
                                          deviceRect.right, deviceRect.top);
                pExport.PixelBounds = pDeviceEnvelope;

                axPageLayoutControl.ActiveView.Output(pExport.StartExporting(), (int)pExport.Resolution,
                                                      ref deviceRect, axPageLayoutControl.ActiveView.Extent, new CancelTrackerClass());
                Application.DoEvents();
                pExport.FinishExporting();
            }
        }
Ejemplo n.º 2
0
        /// <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();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 根据文件路径和路径中的扩展名,来决定生成导出不同类型图片的Export对象
        /// </summary>
        /// <param name="picPath">导出的图片的路径</param>
        /// <param name="resolution"></param>
        /// <returns></returns>
        private static IExport CreateExport(string picPath, double resolution)
        {
            IExport export;
            string  extension = System.IO.Path.GetExtension(picPath)?.ToLower();

            switch (extension)
            {
            case ".jpg": export = new ExportJPEGClass(); break;

            case ".tiff": export = new ExportTIFFClass(); break;

            case ".bmp": export = new ExportBMPClass(); break;

            case ".emf": export = new ExportEMFClass(); break;

            case ".png": export = new ExportPNGClass(); break;

            case ".gif": export = new ExportGIFClass(); break;

            case ".pdf": export = new ExportPDFClass(); break;

            case ".eps": export = new ExportPSClass(); break;

            case ".ai": export = new ExportAIClass(); break;

            case ".svg": export = new ExportSVGClass(); break;

            default: throw new Exception("不支持的图片输出格式!(程序支持的图片格式包括:jpg,tiff,bmp,emf,png,gif,pdf,eps,ai,svg)");
            }

            export.ExportFileName = picPath;
            export.Resolution     = resolution;
            return(export);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 出图
        /// </summary>
        /// <param name="pActiveView"></param>
        /// <param name="fileName"></param>
        public static void ExporterMap(IActiveView pActiveView, string fileName)
        {
            IExport pExporter = new ExportJPEGClass();
            //IEnvelope是指地物的外接矩形,用来表示地物图形的大体位置和形状,一般可用于检索地物,判断地物间的拓扑关系,
            //可以使得检索、判断的速度加快,因为有了IEnvelope,可以首先判断该外接矩形是否在检索范围内,而判断一个外接矩形是比较简单的。
            IEnvelope pEnvelope = new EnvelopeClass();
            // 设置跟踪取消对象   可用于取消操作
            ITrackCancel pTrackCancel = new CancelTrackerClass();
            tagRECT      ptagRECT;

            ptagRECT.left   = 0;
            ptagRECT.top    = 0;
            ptagRECT.right  = (int)pActiveView.Extent.Width;
            ptagRECT.bottom = (int)pActiveView.Extent.Height;
            // 获取输出分辨率 96 ——高清
            int pResolution = (int)(pActiveView.ScreenDisplay.DisplayTransformation.Resolution);

            // 设置一个边框范围
            pEnvelope.PutCoords(ptagRECT.left, ptagRECT.bottom, ptagRECT.right, ptagRECT.top);
            //出图分辨率
            pExporter.Resolution     = pResolution;
            pExporter.ExportFileName = fileName;
            // 将打印像素范围 设置给输出对象
            pExporter.PixelBounds = pEnvelope;
            // 进行视图控件的视图输出操作,设置对应参数
            pActiveView.Output(pExporter.StartExporting(), pResolution, ref ptagRECT, pActiveView.Extent, pTrackCancel);
            pExporter.FinishExporting();
            //释放资源
            System.Runtime.InteropServices.Marshal.ReleaseComObject(pExporter);
        }
Ejemplo n.º 5
0
        /// <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);
        }
Ejemplo n.º 6
0
        public static bool OutputJPEG(IActiveView activeView, string pathFileName)
        {
            //parameter check
            if (activeView == null || !(pathFileName.EndsWith(".jpg")))
            {
                return(false);
            }

            IExport export = new ExportJPEGClass();

            export.ExportFileName = pathFileName;

            // Microsoft Windows default DPI resolution
            export.Resolution = 96;
            tagRECT exportRECT = activeView.ExportFrame;

            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.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);

            // Finish writing the export file and cleanup any intermediate files
            export.FinishExporting();
            export.Cleanup();

            return(true);
        }
        /// <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();
        }
Ejemplo n.º 8
0
        public static void ExportView(IActiveView activeView, IGeometry pGeo, int OutputResolution, int Width,
                                      int Height, string ExpPath, bool bRegion)
        {
            IExport   pExport;
            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;
            if (bRegion)
            {
                //删除区域导出拖出的多边形框
                activeView.GraphicsContainer.DeleteAllElements();
                activeView.Refresh();
            }
            IEnvelope envelope = new EnvelopeClass();

            envelope.PutCoords(exportRect.left, exportRect.top, exportRect.right, exportRect.bottom);
            pExport.PixelBounds = envelope;
            activeView.Output(pExport.StartExporting(), OutputResolution, ref exportRect, pEnvelope, null);
            pExport.FinishExporting();
            pExport.Cleanup();
        }
Ejemplo n.º 9
0
        private void ShowOutputFileDialog(IActiveView docActiveView, int iOutputResolution = 320)
        {
            IExport            docExport;
            IPrintAndExport    docPrintExport;
            IWorldFileSettings worldFileSetting;
            //string localFilePath, fileNameExt, newFileName, FilePath;
            SaveFileDialog sfd = new SaveFileDialog();

            //设置对话框标题
            sfd.Title = "地图输出";
            //设置文件类型
            sfd.Filter = "EMF(*.emf)|*.emf|AI (*.ai) |*.ai|PDF (*.pdf)|*.pdf |SVG (*.svg)| *.svg|TIFF(*.tif)|*.tif|JPEG (*.jpg)| *.jpg|PNG (*.png)| *.png";
            //设置默认文件类型显示顺序
            sfd.FilterIndex = 5;
            //保存对话框是否记忆上次打开的目录
            sfd.RestoreDirectory = true;
            //设置默认的文件名
            int start = m_mapDocumentName.LastIndexOf("\\");
            int end   = m_mapDocumentName.LastIndexOf(".");

            sfd.FileName = m_mapDocumentName.Substring(start + 1, end - start - 1);
            //点了保存按钮进入
            if (sfd.ShowDialog() == DialogResult.OK && sfd.FileName != "")
            {
                switch (sfd.FilterIndex)
                {
                case 1: { docExport = new ExportEMFClass(); break; }

                case 2: { docExport = new ExportAIClass(); break; }

                case 3: { docExport = new ExportPDFClass(); break; }

                case 4: { docExport = new ExportSVGClass(); break; }

                case 5:
                {
                    docExport = new ExportTIFFClass();
                    IExportTIFF exportTiff = docExport as IExportTIFF;
                    exportTiff.GeoTiff         = true;
                    exportTiff.CompressionType = esriTIFFCompression.esriTIFFCompressionLZW;
                    break;
                }     //对于TIFF格式导出带有地理配准的文件

                case 6: { docExport = new ExportJPEGClass(); break; }

                case 7: { docExport = new ExportPNGClass(); break; }

                default: { docExport = new ExportTIFFClass(); break; }
                }
                docPrintExport   = new PrintAndExportClass();
                worldFileSetting = docExport as IWorldFileSettings;
                string localFilePath = sfd.FileName.ToString(); //获得文件路径
                //string fileNameExt = localFilePath.Substring(localFilePath.LastIndexOf("\\") + 1); //获取文件名,不带路径
                docExport.ExportFileName = localFilePath;
                docPrintExport.Export(docActiveView, docExport, iOutputResolution, true, null);
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Occurs when this command is clicked
 /// </summary>
 public override void OnClick()
 {
     // TODO: Add ControlsExportMapCommandClass.OnClick implementation
     if (m_hookHelper == null)
     {
         return;
     }
     try
     {
         SaveFileDialog saveFileDlg = new SaveFileDialog();
         saveFileDlg.Filter = "(*jpeg)|*jpeg|(*.tif)|*tif|(*.pdf)|*.pdf|(*.bmp)|*.bmp|(*.gif)|*.gif|(*.png)|*.png";
         if (saveFileDlg.ShowDialog() == DialogResult.OK)
         {
             IExport export = null;
             if (1 == saveFileDlg.FilterIndex)
             {
                 export = new ExportJPEGClass(); export.ExportFileName = saveFileDlg.FileName + ".jpeg";
             }
             else if (2 == saveFileDlg.FilterIndex)
             {
                 export = new ExportTIFFClass(); export.ExportFileName = saveFileDlg.FileName + ".tif";
             }
             else if (3 == saveFileDlg.FilterIndex)
             {
                 export = new ExportPDFClass(); export.ExportFileName = saveFileDlg.FileName /* + ".pdf"*/;
             }
             else if (4 == saveFileDlg.FilterIndex)
             {
                 export = new ExportBMPClass(); export.ExportFileName = saveFileDlg.FileName /* + ".bmp"*/;
             }
             else if (5 == saveFileDlg.FilterIndex)
             {
                 export = new ExportGIFClass(); export.ExportFileName = saveFileDlg.FileName /* + ".gif"*/;
             }
             else if (6 == saveFileDlg.FilterIndex)
             {
                 export = new ExportPNGClass(); export.ExportFileName = saveFileDlg.FileName /* + ".png"*/;
             }
             int res = 96;
             export.Resolution = res;
             tagRECT   exportRECT = (m_hookHelper.Hook as IMapControl3).ActiveView.ExportFrame;
             IEnvelope pENV       = new EnvelopeClass();
             pENV.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
             export.PixelBounds = pENV;
             int          Hdc            = export.StartExporting();
             IEnvelope    pVisibleBounds = null;
             ITrackCancel pTrack         = null;
             (m_hookHelper.Hook as IMapControl3).ActiveView.Output(Hdc, (int)export.Resolution, ref exportRECT, pVisibleBounds, pTrack);
             Application.DoEvents();
             export.FinishExporting();
             export.Cleanup();
         }
     }
     catch
     {
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// 导出地图
        /// </summary>
        /// <param name="activeView">当前地图</param>
        /// <param name="geo">几何图形</param>
        /// <param name="OutputResolution">输出分辨率</param>
        /// <param name="width">宽</param>
        /// <param name="height">高</param>
        /// <param name="expPath">输出路径</param>
        /// <param name="isRegion">是否时范围输出</param>
        public static void ExportView(IActiveView activeView, IGeometry geo, int OutputResolution, int width, int height, string expPath, bool isRegion)
        {
            IExport   export     = null;
            IEnvelope envelope   = geo.Envelope;
            string    outputType = System.IO.Path.GetExtension(expPath);

            switch (outputType)
            {
            case ".jpg":
                export = new ExportJPEGClass();
                break;

            case ".bmp":
                export = new ExportBMPClass();
                break;

            case ".gif":
                export = new ExportGIFClass();
                break;

            case ".tif":
                export = new ExportTIFFClass();
                break;

            case ".png":
                export = new ExportPNGClass();
                break;

            case ".pdf":
                export = new ExportPDFClass();
                break;

            default:
                MessageBox.Show("没有输出格式,默认到JPEG格式");
                export = new ExportJPEGClass();
                break;
            }

            export.ExportFileName = expPath;
            tagRECT rect = new tagRECT();

            rect.top   = 0; rect.left = 0;
            rect.right = width; rect.bottom = height;
            if (isRegion)
            {
                activeView.GraphicsContainer.DeleteAllElements();
                activeView.Refresh();
            }
            IEnvelope env = new EnvelopeClass();

            env.PutCoords((double)rect.left, (double)rect.top, (double)rect.right, (double)rect.bottom);
            export.PixelBounds = env;
            activeView.Output(export.StartExporting(), OutputResolution, ref rect, envelope, null);
            export.FinishExporting();
            export.Cleanup();
        }
Ejemplo n.º 12
0
        //使用静态方法提高代码的复用性
        public static void ExportView(IActiveView ActiveView, int _resolution, IGeometry pGeo, int Width, int Height, string pathtxt, bool bRegion)
        {
            IExport   pExort     = null;
            tagRECT   pRect      = new tagRECT();
            IEnvelope pEnvelope  = pGeo.Envelope;
            string    outputType = System.IO.Path.GetExtension(pathtxt).ToLower();

            switch (outputType)
            {
            case ".jpg":
                pExort = new ExportJPEGClass();
                break;

            case ".bmp":
                pExort = new ExportBMPClass();
                break;

            case ".gif":
                pExort = new ExportGIFClass();
                break;

            case ".tif":
                pExort = new ExportTIFFClass();
                break;

            case ".png":
                pExort = new ExportPNGClass();
                break;

            case ".pdf":
                pExort = new ExportPDFClass();
                break;

            default:
                MessageBox.Show("未设置输出格式,默认为jpg格式", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                pExort = new ExportJPEGClass();
                break;
            }
            pExort.ExportFileName = pathtxt;
            pRect.left            = 0; pRect.top = 0;
            pRect.right           = Width; pRect.bottom = Height;
            //
            if (bRegion)
            {
                ActiveView.GraphicsContainer.DeleteAllElements();
                ActiveView.Refresh();
            }
            //获取输出影像范围的矩形大小
            IEnvelope envelope = new EnvelopeClass();

            envelope.PutCoords((double)pRect.left, (double)pRect.top, (double)pRect.right, (double)pRect.bottom);
            pExort.PixelBounds = envelope;
            ActiveView.Output(pExort.StartExporting(), _resolution, ref pRect, pEnvelope, null);
            pExort.FinishExporting();
            pExort.Cleanup();
        }
Ejemplo n.º 13
0
        private void button_save_Click(object sender, EventArgs e)
        {
            IActiveView     docActiveView     = axPageLayoutControl1.ActiveView;
            IExport         docExport         = new ExportJPEGClass();
            IPrintAndExport docPrintExport    = new PrintAndExportClass();
            int             iOutputResolution = 300;

            //设置输出文件名
            docExport.ExportFileName = "D:\\a_gis工程设计实践课\\盗墓难度专题图.JPG";
            //输出当前视图到输出文件
            docPrintExport.Export(docActiveView, docExport, iOutputResolution, true, null);
        }
Ejemplo n.º 14
0
        private void MapSelectPrint()//拉框打印框内地图
        {
            try
            {
                IEnvelope pEnv = new EnvelopeClass();
                pEnv = axMapControl1.TrackRectangle();
                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;
                    // lScreenResolution =  axPageLayoutControl1.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
                    //MainaxMapControl.ActiveView.ScreenDisplay.DisplayTransformation.set_DeviceFrame(ref deviceRECT);
                    deviceRECT = axMapControl1.ActiveView.ExportFrame;
                    ////////////////////////////
                    //deviceRECT.left = 0;
                    //deviceRECT.top = 0;
                    // deviceRECT.right = (int)pActiveView.Extent.Width;
                    //deviceRECT.bottom = (int)pActiveView.Extent.Height;
                    ///////////////////////////////////

                    IEnvelope pDriverBounds = new EnvelopeClass();
                    //pDriverBounds = MainaxMapControl.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, pEnv, pCancel);
                    pExporter.FinishExporting();
                    pExporter.Cleanup();
                }
            }
            catch (Exception ex)
            { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop); return; }
        }
Ejemplo n.º 15
0
        /// <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();
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 设置导出路径,获取导出工具
        /// </summary>
        /// <returns></returns>
        public static IExport GetExport()
        {
            string filter =
                "JPGE 文件(*.jpeg)|*.jpeg|BMP 文件(*.bmp)|*.bmp|GIF 文件(*.gif)|*.gif|TIF 文件(*.tif)|*.tif|PNG 文件(*.png)|*.png|PDF 文件(*.pdf)|*.pdf";
            string outPath = FileAndFolderDialog.GetSaveFilePath(filter);

            if (string.IsNullOrEmpty(outPath))
            {
                return(null);
            }
            IExport pExport;
            string  sType = System.IO.Path.GetExtension(outPath);

            switch (sType)
            {
            case ".jpeg":
                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 = outPath;
            return(pExport);
        }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 18
0
 /// <summary>
 /// 输出图片
 /// </summary>
 /// <param name="MapCtrl">AxMapControl控件</param>
 public static void ExportFile(AxMapControl MapCtrl)
 {
     try
     {
         SaveFileDialog sfd = new SaveFileDialog();
         sfd.Filter = "(*.tif)|*tif|(*jpg)|*jpg|(*.pdf)|*.pdf|(*.bmp)|*.bmp";
         if (sfd.ShowDialog() == DialogResult.OK)
         {
             IExport pExport = null;
             if (1 == sfd.FilterIndex)
             {
                 pExport = new ExportTIFFClass();
                 pExport.ExportFileName = sfd.FileName + ".tif";
             }
             else if (2 == sfd.FilterIndex)
             {
                 pExport = new ExportJPEGClass(); pExport.ExportFileName = sfd.FileName + ".jpeg";
             }
             else if (3 == sfd.FilterIndex)
             {
                 pExport = new ExportPDFClass(); pExport.ExportFileName = sfd.FileName + ".pdf";
             }
             else if (4 == sfd.FilterIndex)
             {
                 pExport = new ExportBMPClass(); pExport.ExportFileName = sfd.FileName + ".bmp";
             }
             //pExport.ExportFileName = sfd.FileName;
             int res = 96;
             pExport.Resolution = res;
             tagRECT   exportRECT = MapCtrl.ActiveView.ExportFrame;
             IEnvelope pENV       = new EnvelopeClass();
             pENV.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
             pExport.PixelBounds = pENV;
             int          Hdc            = pExport.StartExporting();
             IEnvelope    pVisibleBounds = null;
             ITrackCancel pTrack         = null;
             MapCtrl.ActiveView.Output(Hdc, (int)pExport.Resolution, ref exportRECT, pVisibleBounds, pTrack);
             System.Windows.Forms.Application.DoEvents();
             pExport.FinishExporting();
             pExport.Cleanup();
         }
     }
     catch { }
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Occurs when this command is clicked
 /// </summary>
 public override void OnClick()
 {
     // TODO: Add ControlsExportMapCommandClass.OnClick implementation
     if (m_hookHelper == null) return;
     try
     {
         SaveFileDialog saveFileDlg = new SaveFileDialog();
         saveFileDlg.Filter = "(*jpeg)|*jpeg|(*.tif)|*tif|(*.pdf)|*.pdf|(*.bmp)|*.bmp|(*.gif)|*.gif|(*.png)|*.png";
         if (saveFileDlg.ShowDialog() == DialogResult.OK)
         {
             IExport export = null;
             if (1 == saveFileDlg.FilterIndex)
             { export = new ExportJPEGClass(); export.ExportFileName = saveFileDlg.FileName + ".jpeg"; }
             else if (2 == saveFileDlg.FilterIndex)
             { export = new ExportTIFFClass(); export.ExportFileName = saveFileDlg.FileName + ".tif"; }
             else if (3 == saveFileDlg.FilterIndex)
             { export = new ExportPDFClass(); export.ExportFileName = saveFileDlg.FileName/* + ".pdf"*/; }
             else if (4 == saveFileDlg.FilterIndex)
             { export = new ExportBMPClass(); export.ExportFileName = saveFileDlg.FileName/* + ".bmp"*/; }
             else if (5 == saveFileDlg.FilterIndex)
             { export = new ExportGIFClass(); export.ExportFileName = saveFileDlg.FileName/* + ".gif"*/; }
             else if (6 == saveFileDlg.FilterIndex)
             { export = new ExportPNGClass(); export.ExportFileName = saveFileDlg.FileName/* + ".png"*/; }
             int res = 96;
             export.Resolution = res;
             tagRECT exportRECT = (m_hookHelper.Hook as IMapControl3).ActiveView.ExportFrame;
             IEnvelope pENV = new EnvelopeClass();
             pENV.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
             export.PixelBounds = pENV;
             int Hdc = export.StartExporting();
             IEnvelope pVisibleBounds = null;
             ITrackCancel pTrack = null;
             (m_hookHelper.Hook as IMapControl3).ActiveView.Output(Hdc, (int)export.Resolution, ref exportRECT, pVisibleBounds, pTrack);
             Application.DoEvents();
             export.FinishExporting();
             export.Cleanup();
         }
     }
     catch
     {
     }
 }
Ejemplo n.º 20
0
        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);
        }
Ejemplo n.º 21
0
 public static IExport ExportBase(string FilePath)
 {
     var ext = System.IO.Path.GetExtension(FilePath);
     IExport export = null;
     switch (ext)
     {
         case ".jpeg":
             export = new ExportJPEGClass();
             break;
         case ".bmp":
             export = new ExportBMPClass();
             break;
         case ".png":
             export = new ExportPNGClass();
             break;
         case ".gif":
             export = new ExportGIFClass();
             break;
     }
     return export;
 }
Ejemplo n.º 22
0
        private void ExportActiveViewParameterized(long iOutputResolution, long lResampleRatio, string ExportType, string sOutputDir, string sOutputFileName, Boolean bClipToGraphicsExtent)
        {
            IActiveView            docActiveView = m_hookHelper.ActiveView;
            IExport                docExport;
            long                   iPrevOutputImageQuality;
            IOutputRasterSettings  docOutputRasterSettings;
            IEnvelope              PixelBoundsEnv;
            tagRECT                exportRECT;
            tagRECT                DisplayBounds;
            IDisplayTransformation docDisplayTransformation;
            IPageLayout            docPageLayout;
            IEnvelope              docMapExtEnv;
            long                   hdc;
            long                   tmpDC;
            long                   iScreenResolution;
            bool                   bReenable = false;


            IEnvelope      docGraphicsExtentEnv;
            IUnitConverter pUnitConvertor;

            if (GetFontSmoothing())
            {
                bReenable = true;
                DisableFontSmoothing();
                if (GetFontSmoothing())
                {
                    return;
                }
            }

            if (ExportType == "PDF")
            {
                docExport = new ExportPDFClass();
            }
            else if (ExportType == "EPS")
            {
                docExport = new ExportPSClass();
            }
            else if (ExportType == "AI")
            {
                docExport = new ExportAIClass();
            }
            else if (ExportType == "BMP")
            {
                docExport = new ExportBMPClass();
            }
            else if (ExportType == "TIFF")
            {
                docExport = new ExportTIFFClass();
            }
            else if (ExportType == "SVG")
            {
                docExport = new ExportSVGClass();
            }
            else if (ExportType == "PNG")
            {
                docExport = new ExportPNGClass();
            }
            else if (ExportType == "GIF")
            {
                docExport = new ExportGIFClass();
            }
            else if (ExportType == "EMF")
            {
                docExport = new ExportEMFClass();
            }
            else if (ExportType == "JPEG")
            {
                docExport = new ExportJPEGClass();
            }
            else
            {
                MessageBox.Show("不支持的数据类型 " + ExportType + ", 默认导出为EMF格式的数据");
                ExportType = "EMF";
                docExport  = new ExportEMFClass();
            }


            docOutputRasterSettings = docActiveView.ScreenDisplay.DisplayTransformation as IOutputRasterSettings;
            iPrevOutputImageQuality = docOutputRasterSettings.ResampleRatio;


            if (docExport is IExportImage)
            {
                SetOutputQuality(docActiveView, 1);
            }
            else
            {
                SetOutputQuality(docActiveView, lResampleRatio);
            }

            docExport.ExportFileName = sOutputFileName + "." + docExport.Filter.Split('.')[1].Split('|')[0].Split(')')[0];


            tmpDC             = GetDC(0);
            iScreenResolution = GetDeviceCaps((int)tmpDC, 88); //88 is the win32 const for Logical pixels/inch in X)
            ReleaseDC(0, (int)tmpDC);
            frmSetResolution mSetResolution = new frmSetResolution(iOutputResolution);

            mSetResolution.ShowDialog();
            iOutputResolution    = mSetResolution.m_Resolution;
            docExport.Resolution = iOutputResolution;


            if (docActiveView is IPageLayout)
            {
                DisplayBounds        = docActiveView.ExportFrame;
                docGraphicsExtentEnv = GetGraphicsExtent(docActiveView);
            }
            else
            {
                docDisplayTransformation = docActiveView.ScreenDisplay.DisplayTransformation;
                DisplayBounds            = docDisplayTransformation.get_DeviceFrame();
            }

            PixelBoundsEnv = new Envelope() as IEnvelope;

            if (bClipToGraphicsExtent && (docActiveView is IPageLayout))
            {
                docGraphicsExtentEnv = GetGraphicsExtent(docActiveView);
                docPageLayout        = docActiveView as PageLayout;
                pUnitConvertor       = new UnitConverter();

                PixelBoundsEnv.XMin = 0;
                PixelBoundsEnv.YMin = 0;
                PixelBoundsEnv.XMax = pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.XMax, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution - pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.XMin, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution;
                PixelBoundsEnv.YMax = pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.YMax, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution - pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.YMin, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution;

                exportRECT.bottom = (int)(PixelBoundsEnv.YMax) + 1;
                exportRECT.left   = (int)(PixelBoundsEnv.XMin);
                exportRECT.top    = (int)(PixelBoundsEnv.YMin);
                exportRECT.right  = (int)(PixelBoundsEnv.XMax) + 1;

                docMapExtEnv = docGraphicsExtentEnv;
            }
            else
            {
                double tempratio  = iOutputResolution / iScreenResolution;
                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;
            }
            docExport.PixelBounds = PixelBoundsEnv;

            try
            {
                hdc = docExport.StartExporting();
                docActiveView.Output((int)hdc, (int)docExport.Resolution, ref exportRECT, docMapExtEnv, null);

                docExport.FinishExporting();
                docExport.Cleanup();

                MessageBox.Show("成功导出 " + sOutputDir + sOutputFileName + "." + docExport.Filter.Split('.')[1].Split('|')[0].Split(')')[0] + ".", "输出地图图片", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch
            {
                MessageBox.Show("输出地图图片过程中出现问题!", "输出地图图片", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            finally
            {
                SetOutputQuality(docActiveView, iPrevOutputImageQuality);
                if (bReenable)
                {
                    EnableFontSmoothing();
                    bReenable = false;
                    if (!GetFontSmoothing())
                    {
                        MessageBox.Show("Unable to reenable Font Smoothing", "Font Smoothing error");
                    }
                }


                docMapExtEnv   = null;
                PixelBoundsEnv = null;
            }
        }
    private void ExportActiveViewParameterized(long iOutputResolution, long lResampleRatio, string ExportType, string sOutputDir, Boolean bClipToGraphicsExtent)
    {
    
      /* EXPORT PARAMETER: (iOutputResolution) the resolution requested.
       * EXPORT PARAMETER: (lResampleRatio) Output Image Quality of the export.  The value here will only be used if the export
       * object is a format that allows setting of Output Image Quality, i.e. a vector exporter.
       * The value assigned to ResampleRatio should be in the range 1 to 5.
       * 1 corresponds to "Best", 5 corresponds to "Fast"
       * EXPORT PARAMETER: (ExportType) a string which contains the export type to create.
       * EXPORT PARAMETER: (sOutputDir) a string which contains the directory to output to.
       * EXPORT PARAMETER: (bClipToGraphicsExtent) Assign True or False to determine if export image will be clipped to the graphic 
       * extent of layout elements.  This value is ignored for data view exports
       */

      /* Exports the Active View of the document to selected output format. */
      
                                  // using predefined static member
      IActiveView docActiveView = ArcMap.Document.ActiveView;
      IExport docExport;  
      IPrintAndExport docPrintExport;
      IOutputRasterSettings RasterSettings;    
      string sNameRoot;
      bool bReenable = false;

      if (GetFontSmoothing())
      {
        /* font smoothing is on, disable it and set the flag to reenable it later. */
        bReenable = true;
        DisableFontSmoothing();
        if (GetFontSmoothing())
        {
          //font smoothing is NOT successfully disabled, error out.
          return;
        }
        //else font smoothing was successfully disabled.
      }

      // The Export*Class() type initializes a new export class of the desired type.
      if (ExportType == "PDF")
      {
        docExport = new ExportPDFClass();
      }
      else if (ExportType == "EPS")
      {
        docExport = new ExportPSClass();
      }
      else if (ExportType == "AI")
      {
        docExport = new ExportAIClass();
      }
      else if (ExportType == "BMP")
      {

        docExport = new ExportBMPClass();
      }
      else if (ExportType == "TIFF")
      {
        docExport = new ExportTIFFClass();
      }
      else if (ExportType == "SVG")
      {
        docExport = new ExportSVGClass();
      }
      else if (ExportType == "PNG")
      {
        docExport = new ExportPNGClass();
      }
      else if (ExportType == "GIF")
      {
        docExport = new ExportGIFClass();
      }
      else if (ExportType == "EMF")
      {
        docExport = new ExportEMFClass();
      }
      else if (ExportType == "JPEG")
      {
        docExport = new ExportJPEGClass();
      }
      else
      {
        MessageBox.Show("Unsupported export type " + ExportType + ", defaulting to EMF.");
        ExportType = "EMF";
        docExport = new ExportEMFClass();
      }

      docPrintExport = new PrintAndExportClass();
     
      //set the name root for the export
      sNameRoot = "ExportActiveViewSampleOutput";

      //set the export filename (which is the nameroot + the appropriate file extension)
      docExport.ExportFileName = sOutputDir + sNameRoot + "." + docExport.Filter.Split('.')[1].Split('|')[0].Split(')')[0];

      //Output Image Quality of the export.  The value here will only be used if the export
      // object is a format that allows setting of Output Image Quality, i.e. a vector exporter.
      // The value assigned to ResampleRatio should be in the range 1 to 5.
      // 1 corresponds to "Best", 5 corresponds to "Fast"

      // check if export is vector or raster
      if (docExport is IOutputRasterSettings)
      {
        // for vector formats, assign the desired ResampleRatio to control drawing of raster layers at export time   
        RasterSettings = (IOutputRasterSettings)docExport;
        RasterSettings.ResampleRatio = (int)lResampleRatio;
        
        // NOTE: for raster formats output quality of the DISPLAY is set to 1 for image export 
        // formats by default which is what should be used
      }
      
      docPrintExport.Export(docActiveView, docExport, iOutputResolution, bClipToGraphicsExtent, null);
  
      MessageBox.Show("Finished exporting " + sOutputDir + sNameRoot + "." + docExport.Filter.Split('.')[1].Split('|')[0].Split(')')[0] + ".", "Export Active View Sample");

      if (bReenable)
      {
        /* reenable font smoothing if we disabled it before */
        EnableFontSmoothing();
        bReenable = false;
        if (!GetFontSmoothing())
        {
          //error: cannot reenable font smoothing.
          MessageBox.Show("Unable to reenable Font Smoothing", "Font Smoothing error");
        }
      }
    }
Ejemplo n.º 24
0
        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);
            }
        }
        /// <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();
        }
Ejemplo n.º 26
0
        /// <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;
            }
        }
Ejemplo n.º 27
0
        public void exportMapa(string ExportType, long iOutputResolution, long lResampleRatio, Boolean bClipToGraphicsExtent, string nombreArchivo,string sOutputDir)
        {
            IActiveView docActiveView = ArcMap.Document.ActiveView;
            IExport docExport;
            IPrintAndExport docPrintExport;
            IOutputRasterSettings RasterSettings;
            bool bReenable = false;

            if (GetFontSmoothing())
            {
                /* font smoothing is on, disable it and set the flag to reenable it later. */
                bReenable = true;
                DisableFontSmoothing();
                if (GetFontSmoothing())
                    return;
            }

            // The Export*Class() type initializes a new export class of the desired type.
            if (ExportType == "PDF")
            {
                docExport = new ExportPDFClass();
            }
            else if (ExportType == "EPS")
            {
                docExport = new ExportPSClass();
            }
            else if (ExportType == "AI")
            {
                docExport = new ExportAIClass();
            }
            else if (ExportType == "BMP")
            {
                docExport = new ExportBMPClass();
            }
            else if (ExportType == "TIFF")
            {
                docExport = new ExportTIFFClass();
            }
            else if (ExportType == "SVG")
            {
                docExport = new ExportSVGClass();
            }
            else if (ExportType == "PNG")
            {
                docExport = new ExportPNGClass();
            }
            else if (ExportType == "GIF")
            {
                docExport = new ExportGIFClass();
            }
            else if (ExportType == "EMF")
            {
                docExport = new ExportEMFClass();
            }
            else if (ExportType == "JPEG")
            {
                docExport = new ExportJPEGClass();
            }
            else
            {
                MessageBox.Show("Unsupported export type " + ExportType + ", defaulting to EMF.");
                ExportType = "EMF";
                docExport = new ExportEMFClass();
            }

            docPrintExport = new PrintAndExportClass();

            //set the export filename (which is the nameroot + the appropriate file extension)
            docExport.ExportFileName = sOutputDir + nombreArchivo + "." + docExport.Filter.Split('.')[1].Split('|')[0].Split(')')[0];

            if (docExport is IOutputRasterSettings){
                RasterSettings = (IOutputRasterSettings)docExport;
                RasterSettings.ResampleRatio = (int)lResampleRatio;
            }

            docPrintExport.Export(docActiveView, docExport, iOutputResolution, bClipToGraphicsExtent, null);
            if (bReenable)
            {
                /* reenable font smoothing if we disabled it before */
                EnableFontSmoothing();
                bReenable = false;
                if (!GetFontSmoothing())
                    MessageBox.Show("Unable to reenable Font Smoothing", "Font Smoothing error");
            }
        }
Ejemplo n.º 28
0
        /// <summary>Exports the page layout to a file.</summary>
        /// <param name="pageLayout">The page layout.</param>
        /// <param name="exportPath">The name of the output file.</param>
        /// <param name="exportFormat">The format of the output.</param>
        /// <param name="dpi">The resolution of the output files.</param>
        void ExportPageLayoutToFile(IPageLayout pageLayout, string exportPath, long dpi, ExportFormat exportFormat)
        {
            IExport export = null;

            // Get the color of the backgrounds for formats that support transparent backgrounds.
            IColor bgColor = null;

            switch (exportFormat)
            {
            case ExportFormat.GIF:
            case ExportFormat.PNG:
                IPage page = pageLayout.Page;
                bgColor = page.BackgroundColor;
                break;
            }


            // Set "export" to the proper type of Export*Class, and set parameters specific to that image type.
            switch (exportFormat)
            {
            case ExportFormat.AI:
                export = new ExportAIClass();
                var ai = export as IExportAI2;
                //ai.EmbedFonts = true;
                break;

            case ExportFormat.EMF:
                export = new ExportEMFClass();
                var xEmf = export as IExportEMF;
                //xEmf.Description =
                break;

            case ExportFormat.PS:
                export = new ExportPSClass();
                var xPs = export as IExportPS;
                xPs.EmbedFonts = true;
                //xPs.Emulsion =
                //xPs.Image =
                //xPs.ImageCompression = esriExportImageCompression.esriExportImageCompressionNone
                //xPs.LanguageLevel = esriExportPSLanguageLevel.esriExportPSLevel3
                break;

            case ExportFormat.SVG:
                export = new ExportSVGClass();
                var xSvg = export as IExportSVG;
                //xSvg.Compressed = true;
                //xSvg.EmbedFonts = true;
                break;

            case ExportFormat.PDF:
                export = new ExportPDFClass();
                var xPdf = export as IExportPDF;
                //xPdf.Compressed = true;
                //xPdf.EmbedFonts = true;
                //xPdf.ImageCompression = esriExportImageCompression.esriExportImageCompressionNone
                break;

            case ExportFormat.GIF:
                export = new ExportGIFClass();
                IExportGIF xGif = export as IExportGIF;
                xGif.TransparentColor = bgColor;
                //xGif.BiLevelThreshold =
                //xGif.CompressionType = esriGIFCompression.esriGIFCompressionNone;
                //xGif.InterlaceMode = false;
                break;

            case ExportFormat.PNG:
                export = new ExportPNGClass();
                IExportPNG xPng = export as IExportPNG;
                //xPng.BiLevelThreshold =
                //xPng.InterlaceMode = false;
                xPng.TransparentColor = bgColor;
                break;

            case ExportFormat.BMP:
                export = new ExportBMPClass();
                IExportBMP xBmp = export as IExportBMP;
                //xBmp.BiLevelThreshold =
                //xBmp.RLECompression = true;
                break;

            case ExportFormat.JPEG:
                export = new ExportJPEGClass();
                IExportJPEG xJpg = export as IExportJPEG;
                //xJpg.ProgressiveMode = false;
                //xJpg.Quality = 80;  //The JPEG compression / image quality. Range (0..100). Default is 100 (no compression / best quality).
                break;

            case ExportFormat.TIFF:
                export = new ExportTIFFClass();
                IExportTIFF xTif = export as IExportTIFF;
                //xTif.BiLevelThreshold =
                //xTif.CompressionType =
                //xTif.GeoTiff = true;
                //The JPEG or Deflate (depending on the Compression type) compression / image quality. Range (0..100). Default is 100 (no compression / best quality).
                //xTif.JPEGOrDeflateQuality = 100;
                break;

            default:
                const string MSG_FMT = "Support for \"{0}\" export is not yet implemented.";
                string       message = string.Format(MSG_FMT, Enum.GetName(typeof(ExportFormat), exportFormat));
                throw new NotImplementedException(message);
            }

            IEnvelope pixelEnv   = new EnvelopeClass();
            IEnvelope pageExt    = GetPageExtent(pageLayout);
            IPoint    upperRight = pageExt.UpperRight;

            pixelEnv.PutCoords(0, 0, dpi * upperRight.X, dpi * upperRight.Y);
            export.PixelBounds    = pixelEnv;
            export.Resolution     = dpi;
            export.ExportFileName = exportPath;
            //
            //(device coordinates origin is upper left, ypositive is down)
            tagRECT expRect;

            expRect.left   = (int)export.PixelBounds.LowerLeft.X;
            expRect.bottom = (int)export.PixelBounds.UpperRight.Y;
            expRect.right  = (int)export.PixelBounds.UpperRight.X;
            expRect.top    = (int)export.PixelBounds.LowerLeft.Y;

            _app.StatusBar.set_Message(0, string.Format("exporting \"{0}\"", exportPath));
            long        hdc = export.StartExporting();
            IActiveView av  = (IActiveView)pageLayout;

            av.Output((int)hdc, (int)dpi, ref expRect, null, null);
            export.FinishExporting();
            export.Cleanup();
        }
Ejemplo n.º 29
0
        public static void ExportActiveView(IActiveView pView, long iOutputResolution, long lResampleRatio, 
                    string sExportType, string sOutputDir, string sOutputName,
                    Boolean bClipToGraphicsExtent = true, IEnvelope pEnvelope = null)
        {
            //解决文件名错误
            IActiveView docActiveView = pView;
            IExport docExport;
            long iPrevOutputImageQuality;
            IOutputRasterSettings docOutputRasterSettings;
            IEnvelope PixelBoundsEnv;
            tagRECT exportRECT;
            tagRECT DisplayBounds;
            IDisplayTransformation docDisplayTransformation;
            IPageLayout docPageLayout;
            IEnvelope docMapExtEnv;

            if (pEnvelope == null)
                pEnvelope = GetGraphicsExtent(pView);

            long hdc;
            long tmpDC;
            //string sNameRoot;
            long iScreenResolution;
            bool bReenable = false;

            IEnvelope docGraphicsExtentEnv;
            IUnitConverter pUnitConvertor;
            if (GetFontSmoothing())
            {
                bReenable = true;
                DisableFontSmoothing();
                if (GetFontSmoothing())
                {
                    //font smoothing is NOT successfully disabled, error out.
                    return;
                }
                //else font smoothing was successfully disabled.
            }

            // The Export*Class() type initializes a new export class of the desired type.
            if (String.Compare(sExportType,"PDF",true) == 0)
            {
                docExport = new ExportPDFClass();
            }
            else if (String.Compare(sExportType,"EPS",true) == 0)
            {
                docExport = new ExportPSClass();
            }
            else if (String.Compare(sExportType,"AI",true) == 0)
            {
                docExport = new ExportAIClass();
            }
            else if (String.Compare(sExportType,"BMP",true) == 0)
            {
                docExport = new ExportBMPClass();
            }
            else if (String.Compare(sExportType,"TIFF",true) == 0)
            {
                docExport = new ExportTIFFClass();
            }
            else if (String.Compare(sExportType,"SVG",true) == 0)
            {
                docExport = new ExportSVGClass();
            }
            else if (String.Compare(sExportType,"PNG",true) == 0)
            {
                docExport = new ExportPNGClass();
            }
            else if (String.Compare(sExportType,"GIF",true) == 0)
            {
                docExport = new ExportGIFClass();
            }
            else if (String.Compare(sExportType,"EMF",true) == 0)
            {
                docExport = new ExportEMFClass();
            }
            else if (String.Compare(sExportType,"JPEG",true) == 0 ||
                     String.Compare(sExportType,"JPG",true) == 0)
            {
                docExport = new ExportJPEGClass();
            }
            else
            {
                MessageBox.Show("!!不支持的格式 " + sExportType + ", 默认导出 EMF.");
                sExportType = "EMF";
                docExport = new ExportEMFClass();
            }

            //  save the previous output image quality, so that when the export is complete it will be set back.
            docOutputRasterSettings = docActiveView.ScreenDisplay.DisplayTransformation as IOutputRasterSettings;
            iPrevOutputImageQuality = docOutputRasterSettings.ResampleRatio;

            if (docExport is IExportImage)
            {
                // always set the output quality of the DISPLAY to 1 for image export formats
                SetOutputQuality(docActiveView, 1);
            }
            else
            {
                // for vector formats, assign the desired ResampleRatio to control drawing of raster layers at export time
                SetOutputQuality(docActiveView, lResampleRatio);
            }
            //set the name root for the export
            // sNameRoot = "ExportActiveViewSampleOutput";
            //set the export filename (which is the nameroot + the appropriate file extension)
            docExport.ExportFileName = sOutputDir + "\\" + sOutputName + "." + docExport.Filter.Split('.')[1].Split('|')[0].Split(')')[0];

            tmpDC = GetDC(0);

            iScreenResolution = GetDeviceCaps((int)tmpDC, 88); //88 is the win32 const for Logical pixels/inch in X)

            ReleaseDC(0, (int)tmpDC);
            docExport.Resolution = iOutputResolution;

            if (docActiveView is IPageLayout)
            {
                //get the bounds of the "exportframe" of the active view.
                DisplayBounds = docActiveView.ExportFrame;
                //set up pGraphicsExtent, used if clipping to graphics extent.
                docGraphicsExtentEnv = pEnvelope;
            }
            else
            {
                //Get the bounds of the deviceframe for the screen.
                docDisplayTransformation = docActiveView.ScreenDisplay.DisplayTransformation;
                DisplayBounds = docDisplayTransformation.get_DeviceFrame();
            }
            PixelBoundsEnv = new Envelope() as IEnvelope;
            if (bClipToGraphicsExtent && (docActiveView is IPageLayout))
            {
                docGraphicsExtentEnv = pEnvelope;
                docPageLayout = docActiveView as PageLayout;
                pUnitConvertor = new UnitConverter();
                //assign the x and y values representing the clipped area to the PixelBounds envelope
                PixelBoundsEnv.XMin = 0;
                PixelBoundsEnv.YMin = 0;
                PixelBoundsEnv.XMax = pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.XMax, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution - pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.XMin, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution;
                PixelBoundsEnv.YMax = pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.YMax, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution - pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.YMin, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution;
                //'assign the x and y values representing the clipped export extent to the exportRECT
                exportRECT.bottom = (int)(PixelBoundsEnv.YMax) + 1;
                exportRECT.left = (int)(PixelBoundsEnv.XMin);
                exportRECT.top = (int)(PixelBoundsEnv.YMin);
                exportRECT.right = (int)(PixelBoundsEnv.XMax) + 1;
                //since we're clipping to graphics extent, set the visible bounds.
                docMapExtEnv = docGraphicsExtentEnv;
            }
            else
            {
                double tempratio = iOutputResolution / iScreenResolution;
                double tempbottom = DisplayBounds.bottom * tempratio;
                double tempright = DisplayBounds.right * tempratio;
                //'The values in the exportRECT tagRECT correspond to the width
                //and height to export, measured in pixels with an origin in the top left corner.
                exportRECT.bottom = (int)Math.Truncate(tempbottom);
                exportRECT.left = 0;
                exportRECT.top = 0;
                exportRECT.right = (int)Math.Truncate(tempright);

                //populate the PixelBounds envelope with the values from exportRECT.
                // We need to do this because the exporter object requires an envelope object
                // instead of a tagRECT structure.
                PixelBoundsEnv.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
                //since it's a page layout or an unclipped page layout we don't need docMapExtEnv.
                docMapExtEnv = null;
            }
            // Assign the envelope object to the exporter object's PixelBounds property.  The exporter object
            // will use these dimensions when allocating memory for the export file.
            docExport.PixelBounds = PixelBoundsEnv;
            // call the StartExporting method to tell docExport you're ready to start outputting.
            hdc = docExport.StartExporting();
            // Redraw the active view, rendering it to the exporter object device context instead of the app display.
            // We pass the following values:
            //  * hDC is the device context of the exporter object.
            //  * exportRECT is the tagRECT structure that describes the dimensions of the view that will be rendered.
            // The values in exportRECT should match those held in the exporter object's PixelBounds property.
            //  * docMapExtEnv is an envelope defining the section of the original image to draw into the export object.
            docActiveView.Output((int)hdc, (int)docExport.Resolution, ref exportRECT, docMapExtEnv, null);
            //finishexporting, then cleanup.
            docExport.FinishExporting();
            docExport.Cleanup();
            MessageBox.Show("成功导出地图: " + docExport.ExportFileName, "提示");
            //set the output quality back to the previous value
            SetOutputQuality(docActiveView, iPrevOutputImageQuality);

            if (bReenable)
            {
                EnableFontSmoothing();
                bReenable = false;
                if (!GetFontSmoothing())
                {
                    //error: cannot reenable font smoothing.
                    MessageBox.Show("Unable to reenable Font Smoothing", "Font Smoothing error");
                }
            }

            docMapExtEnv = null;
            PixelBoundsEnv = null;
        }
Ejemplo n.º 30
0
        private void mapOutPutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IActiveView     docActiveView;
            IExport         docExport;
            IPrintAndExport docPrintExport;
            //设置图片分辨率,下方注释掉的代码为根据监听当前窗口的分辨率来设置分辨率
            //经测试发现将分辨率直接设置为300的情况下导出地图更清晰
            int iOutputResolution = 300;

            //double iOutputResolution = axMapControl1.ActiveView.ScreenDisplay.DisplayTransformation.Resolution;

            if (pageLayout.Checked == true)//输出pagelayout
            {
                docActiveView = axMapControl1.ActiveView;
            }
            else  //输出mapview
            {
                docActiveView = axPageLayoutControl2.ActiveView;
            }
            // docExport = new ExportJPEGClass();
            //docPrintExport = new PrintAndExportClass();

            //设置输出的文件名
            //选择保存格式,可以保存为jpg,png和pdf
            SaveFileDialog savefiledialog1 = new SaveFileDialog();

            savefiledialog1.DefaultExt = ".jpg";
            savefiledialog1.Filter     = "JPG Documents (*.jpg)|*.jpg|PDF Documents(*.pdf)|*.pdf|PNG Documents(*.png)|*.png";
            savefiledialog1.ShowDialog();
            docExport = new ExportJPEGClass();
            //设置保存的文件名
            string Outpath = savefiledialog1.FileName;
            //得到输出文件的扩展名
            string fileExtName = Outpath.Substring(Outpath.LastIndexOf(".") + 1).ToString();

            if (fileExtName != "")
            {
                switch (fileExtName)
                {
                case "jpg":
                    docExport = new ExportJPEGClass();
                    break;

                case "pdf":
                    docExport = new ExportPDFClass();
                    break;

                case "png":
                    docExport = new ExportPNGClass();
                    break;

                default:
                    MessageBox.Show("只能保存为: jpg,pdf,png 格式");
                    break;
                }
            }
            docPrintExport           = new PrintAndExportClass();
            docExport.ExportFileName = Outpath;



            //输出当前视图到输出文件
            docPrintExport.Export(docActiveView, docExport, iOutputResolution, true, null);
        }
Ejemplo n.º 31
0
        // Exports a given page layout or map frame to a variety of image formats, returns the image file path
        public static string exportImage(IMxDocument pMxDoc, string exportType, string dpi, string pathDocumentName, string mapFrameName)
        {
            // Define the activeView as either the page layout or the map frame
            // If the mapFrameName variable is null then the activeView is the page, otherwise it is set to the map frame name specified
            IMap        pMap;
            IActiveView pActiveView = null;
            IMaps       pMaps       = pMxDoc.Maps;
            // Also construct output filename depending on the activeView / mapFrame input
            string pathFileName = string.Empty;

            if (mapFrameName == null)
            {
                pActiveView  = pMxDoc.ActiveView;
                pathFileName = @pathDocumentName + "-" + dpi.ToString() + "dpi." + exportType;
            }
            else if (mapFrameName != null && PageLayoutProperties.detectMapFrame(pMxDoc, mapFrameName))
            {
                for (int i = 0; i <= pMaps.Count - 1; i++)
                {
                    pMap = pMaps.get_Item(i);
                    if (pMap.Name == mapFrameName)
                    {
                        pActiveView = pMap as IActiveView;
                    }
                }
                pathFileName = @pathDocumentName + "-mapframe-" + dpi.ToString() + "dpi." + exportType;
            }
            else
            {
                return(null);
            }

            //Declare the export variable and set the file and path from the parameters
            IExport docExport;

            //parameter check
            if (pActiveView == null)
            {
                return(null);
            }
            // The Export*Class() type initializes a new export class of the desired type.
            if (exportType == "pdf")
            {
                docExport = new ExportPDFClass();
            }
            else if (exportType == "eps")
            {
                docExport = new ExportPSClass();
            }
            else if (exportType == "ai")
            {
                docExport = new ExportAIClass();
            }
            else if (exportType == "bmp")
            {
                docExport = new ExportBMPClass();
            }
            else if (exportType == "tiff")
            {
                docExport = new ExportTIFFClass();
            }
            else if (exportType == "svg")
            {
                docExport = new ExportSVGClass();
            }
            else if (exportType == "png")
            {
                docExport = new ExportPNGClass();
            }
            else if (exportType == "gif")
            {
                docExport = new ExportGIFClass();
            }
            else if (exportType == "emf")
            {
                docExport = new ExportEMFClass();
            }
            else if (exportType == "jpeg")
            {
                IExportJPEG m_export;
                docExport = new ExportJPEGClass();
                if (docExport is IExportJPEG)
                {
                    m_export = (IExportJPEG)docExport;
                    m_export.ProgressiveMode = false;   //hardcoded progressive mode value here
                    m_export.Quality         = 80;      //hardcoded quality value here
                    docExport = (IExport)m_export;
                }
            }
            else
            {
                return(pathFileName);
            }

            docExport.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 = Convert.ToInt32(dpi);

            docExport.Resolution = outputResolution;

            // If input type is map frame calculate the export rectangle

            tagRECT exportRECT; // This is a structure

            exportRECT.left   = 0;
            exportRECT.top    = 0;
            exportRECT.right  = pActiveView.ExportFrame.right * (outputResolution / screenResolution);
            exportRECT.bottom = pActiveView.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);
            docExport.PixelBounds = envelope;

            try
            {
                System.Int32 hDC = docExport.StartExporting();
                pActiveView.Output(hDC, (System.Int16)docExport.Resolution, ref exportRECT, null, null); // Explicit Cast and 'ref' keyword needed
                docExport.FinishExporting();
                docExport.Cleanup();
            }
            catch (Exception e)
            {
                Debug.WriteLine("Error writing to file, probably a file permissions error.  Check the exception message below for details.");
                Debug.WriteLine(e.Message);
            }

            //Return the path of the file
            return(pathFileName);
        }
Ejemplo n.º 32
0
        /// <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);
        }
Ejemplo n.º 33
0
 private IExport ExportBase()
 {
     this.Ext = System.IO.Path.GetExtension(this.FilePath);
     IExport export = null;
     switch (this.Ext)
     {
         case ".jpeg":
             export = new ExportJPEGClass();
             break;
         case ".bmp":
             export = new ExportBMPClass();
             break;
         case ".png":
             export = new ExportPNGClass();
             break;
         case ".gif":
             export = new ExportGIFClass();
             break;
     }
     return export;
 }
Ejemplo n.º 34
0
        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; }
        }
Ejemplo n.º 35
0
        private void ExportActiveViewParameterized(long iOutputResolution, long lResampleRatio, string ExportType, string sOutputDir,string sOutputFileName, Boolean bClipToGraphicsExtent)
        {
            IActiveView docActiveView = m_hookHelper.ActiveView;
            IExport docExport;
            long iPrevOutputImageQuality;
            IOutputRasterSettings docOutputRasterSettings;
            IEnvelope PixelBoundsEnv;
            tagRECT exportRECT;
            tagRECT DisplayBounds;
            IDisplayTransformation docDisplayTransformation;
            IPageLayout docPageLayout;
            IEnvelope docMapExtEnv;
            long hdc;
            long tmpDC;
            long iScreenResolution;
            bool bReenable = false;

            IEnvelope docGraphicsExtentEnv;
            IUnitConverter pUnitConvertor;

            if (GetFontSmoothing())
            {
                bReenable = true;
                DisableFontSmoothing();
                if (GetFontSmoothing())
                {
                    return;
                }
            }

            if (ExportType == "PDF")
            {
                docExport = new ExportPDFClass();
            }
            else if (ExportType == "EPS")
            {
                docExport = new ExportPSClass();
            }
            else if (ExportType == "AI")
            {
                docExport = new ExportAIClass();
            }
            else if (ExportType == "BMP")
            {

                docExport = new ExportBMPClass();
            }
            else if (ExportType == "TIFF")
            {
                docExport = new ExportTIFFClass();
            }
            else if (ExportType == "SVG")
            {
                docExport = new ExportSVGClass();
            }
            else if (ExportType == "PNG")
            {
                docExport = new ExportPNGClass();
            }
            else if (ExportType == "GIF")
            {
                docExport = new ExportGIFClass();
            }
            else if (ExportType == "EMF")
            {
                docExport = new ExportEMFClass();
            }
            else if (ExportType == "JPEG")
            {
                docExport = new ExportJPEGClass();
            }
            else
            {
                MessageBox.Show("��֧�ֵ��������� " + ExportType + ", Ĭ�ϵ���ΪEMF��ʽ������");
                ExportType = "EMF";
                docExport = new ExportEMFClass();
            }

            docOutputRasterSettings = docActiveView.ScreenDisplay.DisplayTransformation as IOutputRasterSettings;
            iPrevOutputImageQuality = docOutputRasterSettings.ResampleRatio;

            if (docExport is IExportImage)
            {
                SetOutputQuality(docActiveView, 1);
            }
            else
            {
                SetOutputQuality(docActiveView, lResampleRatio);
            }

            docExport.ExportFileName = sOutputFileName + "." + docExport.Filter.Split('.')[1].Split('|')[0].Split(')')[0];

            tmpDC = GetDC(0);
            iScreenResolution = GetDeviceCaps((int)tmpDC, 88); //88 is the win32 const for Logical pixels/inch in X)
            ReleaseDC(0, (int)tmpDC);
            frmSetResolution mSetResolution = new frmSetResolution(iOutputResolution);
            mSetResolution.ShowDialog();
            iOutputResolution = mSetResolution.m_Resolution ;
            docExport.Resolution = iOutputResolution;

            if (docActiveView is IPageLayout)
            {
                DisplayBounds = docActiveView.ExportFrame;
                docGraphicsExtentEnv = GetGraphicsExtent(docActiveView);
            }
            else
            {
                docDisplayTransformation = docActiveView.ScreenDisplay.DisplayTransformation;
                DisplayBounds = docDisplayTransformation.get_DeviceFrame();
            }

            PixelBoundsEnv = new Envelope() as IEnvelope;

            if (bClipToGraphicsExtent && (docActiveView is IPageLayout))
            {
                docGraphicsExtentEnv = GetGraphicsExtent(docActiveView);
                docPageLayout = docActiveView as PageLayout;
                pUnitConvertor = new UnitConverter();

                PixelBoundsEnv.XMin = 0;
                PixelBoundsEnv.YMin = 0;
                PixelBoundsEnv.XMax = pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.XMax, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution - pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.XMin, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution;
                PixelBoundsEnv.YMax = pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.YMax, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution - pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.YMin, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution;

                exportRECT.bottom = (int)(PixelBoundsEnv.YMax) + 1;
                exportRECT.left = (int)(PixelBoundsEnv.XMin);
                exportRECT.top = (int)(PixelBoundsEnv.YMin);
                exportRECT.right = (int)(PixelBoundsEnv.XMax) + 1;

                docMapExtEnv = docGraphicsExtentEnv;
            }
            else
            {
                double tempratio = iOutputResolution / iScreenResolution;
                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;
            }
            docExport.PixelBounds = PixelBoundsEnv;

            try
            {
                hdc = docExport.StartExporting();
                docActiveView.Output((int)hdc, (int)docExport.Resolution, ref exportRECT, docMapExtEnv, null);

                docExport.FinishExporting();
                docExport.Cleanup();

                MessageBox.Show("�ɹ����� " + sOutputDir + sOutputFileName + "." + docExport.Filter.Split('.')[1].Split('|')[0].Split(')')[0] + ".", "�����ͼͼƬ", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }
            catch
            {
                MessageBox.Show("�����ͼͼƬ�����г������⣡", "�����ͼͼƬ", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            finally
            {
                SetOutputQuality(docActiveView, iPrevOutputImageQuality);
                if (bReenable)
                {
                    EnableFontSmoothing();
                    bReenable = false;
                    if (!GetFontSmoothing())
                    {
                        MessageBox.Show("Unable to reenable Font Smoothing", "Font Smoothing error");
                    }
                }

                docMapExtEnv = null;
                PixelBoundsEnv = null;
            }
        }
 private IExport CreateExport(string PathName, int iResampleRatio)
 {
     IExport docExport;
     string sExtionsName = PathName.Substring(PathName.LastIndexOf(".") + 1);
     sExtionsName = sExtionsName.ToUpper();
     switch (sExtionsName)
     {
     case "PDF":
         docExport = new ExportPDFClass();
         break;
     case "EPS":
         docExport = new ExportPSClass();
         break;
     case "AI":
         docExport = new ExportAIClass();
         break;
     case "BMP":
         docExport = new ExportBMPClass();
         break;
     case "TIFF":
         docExport = new ExportTIFFClass();
         break;
     case "TIF":
         docExport = new ExportTIFFClass();
         break;
     case "SVG":
         docExport = new ExportSVGClass();
         break;
     case "PNG":
         docExport = new ExportPNGClass();
         break;
     case "GIF":
         docExport = new ExportGIFClass();
         break;
     case "EMF":
         docExport = new ExportEMFClass();
         break;
     case "JPEG":
         docExport = new ExportJPEGClass();
         break;
     case "JPG":
         docExport = new ExportJPEGClass();
         break;
     default:
         docExport = new ExportJPEGClass();
         break;
     }
     if (docExport is IOutputRasterSettings)
     {
     if (iResampleRatio < 1) iResampleRatio = 1;
     if (iResampleRatio > 5) iResampleRatio = 5;
     IOutputRasterSettings RasterSettings = (IOutputRasterSettings)docExport;
     RasterSettings.ResampleRatio = iResampleRatio;
     }
     docExport.ExportFileName = PathName;
     return docExport;
 }
Ejemplo n.º 37
0
        //输出当前地图为图片
        public static string ExportImage(IActiveView pActiveView)
        {
            if (pActiveView == null)
            {
                return null;
            }
            try
            {
                SaveFileDialog pSaveFileDialog = new SaveFileDialog();
                pSaveFileDialog.Filter = "JPEG(*.jpg)|*.jpg|AI(*.ai)|*.ai|BMP(*.BMP)|*.bmp|EMF(*.emf)|*.emf|GIF(*.gif)|*.gif|PDF(*.pdf)|*.pdf|PNG(*.png)|*.png|EPS(*.eps)|*.eps|SVG(*.svg)|*.svg|TIFF(*.tif)|*.tif";
                pSaveFileDialog.Title = "输出地图";
                pSaveFileDialog.RestoreDirectory = true;
                pSaveFileDialog.FilterIndex = 1;
                if (pSaveFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return null;
                }
                string FileName = pSaveFileDialog.FileName;
                IExport pExporter = null;
                switch (pSaveFileDialog.FilterIndex)
                {
                    case 1:
                        pExporter = new ExportJPEGClass();
                        break;
                    case 2:
                        pExporter = new ExportBMPClass();
                        break;
                    case 3:
                        pExporter = new ExportEMFClass();
                        break;
                    case 4:
                        pExporter = new ExportGIFClass();
                        break;
                    case 5:
                        pExporter = new ExportAIClass();
                        break;
                    case 6:
                        pExporter = new ExportPDFClass();
                        break;
                    case 7:
                        pExporter = new ExportPNGClass();
                        break;
                    case 8:
                        pExporter = new ExportPSClass();
                        break;
                    case 9:
                        pExporter = new ExportSVGClass();
                        break;
                    case 10:
                        pExporter = new ExportTIFFClass();
                        break;
                    default:
                        MessageBox.Show("输出格式错误");
                        return null;
                }
                IEnvelope pEnvelope = new EnvelopeClass();
                ITrackCancel pTrackCancel = new CancelTrackerClass();
                tagRECT ptagRECT;
                ptagRECT = pActiveView.ScreenDisplay.DisplayTransformation.get_DeviceFrame();

                int pResolution = (int)(pActiveView.ScreenDisplay.DisplayTransformation.Resolution);

                pEnvelope.PutCoords(ptagRECT.left, ptagRECT.bottom, ptagRECT.right, ptagRECT.top);
                pExporter.Resolution = pResolution;
                pExporter.ExportFileName = FileName;
                pExporter.PixelBounds = pEnvelope;
                pActiveView.Output(pExporter.StartExporting(), pResolution, ref ptagRECT, pActiveView.Extent, pTrackCancel);
                pExporter.FinishExporting();
                //释放资源
                pSaveFileDialog.Dispose();
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pExporter);
                return FileName;
            }
            catch
            {
                return null;

            }
        }
Ejemplo n.º 38
0
        /// <summary>
        /// 输出图片
        /// </summary>
        /// <param name="activeView"></param>
        /// <param name="filename"></param>
        /// <param name="format"></param>
        /// <param name="resolution"></param>
        public static void ExportRasterFile(IActiveView activeView, string filename, string format, double resolution)
        {
            if (activeView == null || filename.Length == 0)
            {
                return;
            }

            double screenResolution = resolution;
            double outputResolution = resolution;

            IExport export = null;

            switch (format)
            {
            case "PDF":
                export = new ExportPDFClass();

                IExportVectorOptions exportVectorOptions = export as IExportVectorOptions;
                exportVectorOptions.PolygonizeMarkers = true;

                IExportPDF exportPDF = export as IExportPDF;
                exportPDF.EmbedFonts = true;
                break;

            case "BMP":
                export = new ExportBMPClass();
                break;

            case "JPG":
                export = new ExportJPEGClass();
                if (filename.IndexOf("彩信") != -1)
                {
                    IExportJPEG exportJPEG = export as IExportJPEG;
                    exportJPEG.Quality = 70;
                    outputResolution   = 70.0;
                }
                break;

            case "PNG":
                export = new ExportPNGClass();
                break;

            case "TIF":
                export = new ExportTIFFClass();
                break;

            case "GIF":
                export = new ExportGIFClass();
                break;

            case "EMF":
                export = new ExportEMFClass();
                break;

            case "SVG":
                export = new ExportSVGClass();
                break;

            case "AI":
                export = new ExportAIClass();
                break;

            case "EPS":
                export = new ExportPSClass();
                break;
            }

            IGraphicsContainer    docGraphicsContainer;
            IElement              docElement;
            IOutputRasterSettings docOutputRasterSettings;
            IMapFrame             docMapFrame;
            IActiveView           tmpActiveView;
            IOutputRasterSettings doOutputRasterSettings;

            if (activeView is IMap)
            {
                doOutputRasterSettings = activeView.ScreenDisplay.DisplayTransformation as IOutputRasterSettings;
                doOutputRasterSettings.ResampleRatio = 3;
            }
            else if (activeView is IPageLayout)
            {
                doOutputRasterSettings = activeView.ScreenDisplay.DisplayTransformation as IOutputRasterSettings;
                doOutputRasterSettings.ResampleRatio = 4;
                //and assign ResampleRatio to the maps in the PageLayout.
                docGraphicsContainer = activeView as IGraphicsContainer;
                docGraphicsContainer.Reset();
                docElement = docGraphicsContainer.Next();
                int c = 0;

                while (docElement != null)
                {
                    c += 1;
                    if (docElement is IMapFrame)
                    {
                        docMapFrame             = docElement as IMapFrame;
                        tmpActiveView           = docMapFrame.Map as IActiveView;
                        docOutputRasterSettings = tmpActiveView.ScreenDisplay.DisplayTransformation as IOutputRasterSettings;
                        docOutputRasterSettings.ResampleRatio = 1;
                    }
                    docElement = docGraphicsContainer.Next();
                }


                docMapFrame          = null;
                docGraphicsContainer = null;
                tmpActiveView        = null;
            }
            else
            {
                docOutputRasterSettings = null;
            }
            //end



            export.ExportFileName = filename;
            export.Resolution     = outputResolution;


            tagRECT exportRECT = activeView.ExportFrame;

            exportRECT.right  = (int)(exportRECT.right * (outputResolution / screenResolution));
            exportRECT.bottom = (int)(exportRECT.bottom * (outputResolution / screenResolution));

            IEnvelope envelope = new EnvelopeClass();

            envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
            export.PixelBounds = envelope;

            int hDC = export.StartExporting();

            activeView.Output(hDC, Convert.ToInt32(export.Resolution), ref exportRECT, null, null);
            export.FinishExporting();
            export.Cleanup();
        }
Ejemplo n.º 39
0
        /// <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);
        }
Ejemplo n.º 40
0
        /// <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
            //{

            //}
        }
Ejemplo n.º 41
0
        private void ExportActiveViewParameterized(long iOutputResolution, long lResampleRatio, string ExportType, string sOutputName, Boolean bClipToGraphicsExtent)
        {
            /* EXPORT PARAMETER: (iOutputResolution) the resolution requested.
             * EXPORT PARAMETER: (lResampleRatio) Output Image Quality of the export.  The value here will only be used if the export
             * object is a format that allows setting of Output Image Quality, i.e. a vector exporter.
             * The value assigned to ResampleRatio should be in the range 1 to 5.
             * 1 corresponds to "Best", 5 corresponds to "Fast"
             * EXPORT PARAMETER: (ExportType) a string which contains the export type to create.
             * EXPORT PARAMETER: (sOutputDir) a string which contains the directory to output to.
             * EXPORT PARAMETER: (bClipToGraphicsExtent) Assign True or False to determine if export image will be clipped to the graphic
             * extent of layout elements.  This value is ignored for data view exports
             */

            /* Exports the Active View of the document to selected output format. */
            IActiveView docActiveView = null;

            if (m_hookHelper == null)
            {
                docActiveView = ExportActiveView;
            }
            else
            {
                docActiveView = m_hookHelper.ActiveView;
            }

            IExport docExport;
            long    iPrevOutputImageQuality;
            IOutputRasterSettings docOutputRasterSettings;
            IEnvelope             PixelBoundsEnv;
            tagRECT exportRECT;
            tagRECT DisplayBounds;
            IDisplayTransformation docDisplayTransformation;
            IPageLayout            docPageLayout;
            IEnvelope docMapExtEnv;
            long      hdc;
            long      tmpDC;
            string    sNameRoot;
            long      iScreenResolution;
            bool      bReenable = false;


            IEnvelope      docGraphicsExtentEnv;
            IUnitConverter pUnitConvertor;

            if (GetFontSmoothing())
            {
                /* font smoothing is on, disable it and set the flag to reenable it later. */
                bReenable = true;
                DisableFontSmoothing();
                if (GetFontSmoothing())
                {
                    //font smoothing is NOT successfully disabled, error out.
                    return;
                }
                //else font smoothing was successfully disabled.
            }


            // The Export*Class() type initializes a new export class of the desired type.

            if (ExportType == "PDF")
            {
                docExport = new ExportPDFClass();
                IExportPDF pExPDF = docExport as IExportPDF;
                pExPDF.EmbedFonts = true;
            }
            else if (ExportType == "EPS")
            {
                docExport = new ExportPSClass();
            }
            else if (ExportType == "AI")
            {
                docExport = new ExportAIClass();
            }
            else if (ExportType == "BMP")
            {
                docExport = new ExportBMPClass();
            }
            else if (ExportType == "TIFF")
            {
                docExport = new ExportTIFFClass();
            }
            else if (ExportType == "SVG")
            {
                docExport = new ExportSVGClass();
            }
            else if (ExportType == "PNG")
            {
                docExport = new ExportPNGClass();
            }
            else if (ExportType == "GIF")
            {
                docExport = new ExportGIFClass();
            }
            else if (ExportType == "EMF")
            {
                docExport = new ExportEMFClass();
            }
            else if (ExportType == "JPG")
            {
                docExport = new ExportJPEGClass();
            }
            else
            {
                MessageBox.Show("Unsupported export type " + ExportType + ", defaulting to EMF.");
                ExportType = "EMF";
                docExport  = new ExportEMFClass();
            }


            //  save the previous output image quality, so that when the export is complete it will be set back.
            docOutputRasterSettings = docActiveView.ScreenDisplay.DisplayTransformation as IOutputRasterSettings;
            iPrevOutputImageQuality = docOutputRasterSettings.ResampleRatio;


            if (docExport is IExportImage)
            {
                // always set the output quality of the DISPLAY to 1 for image export formats
                SetOutputQuality(docActiveView, 1);
            }
            else
            {
                // for vector formats, assign the desired ResampleRatio to control drawing of raster layers at export time
                SetOutputQuality(docActiveView, lResampleRatio);
            }

            //set the name root for the export
            sNameRoot = docActiveView.FocusMap.Name;

            //set the export filename (which is the nameroot + the appropriate file extension)
            docExport.ExportFileName = sOutputName;


            /* Get the device context of the screen */
            tmpDC = GetDC(0);
            /* Get the screen resolution. */
            iScreenResolution = GetDeviceCaps((int)tmpDC, 88); //88 is the win32 const for Logical pixels/inch in X)
            /* release the DC. */
            ReleaseDC(0, (int)tmpDC);
            docExport.Resolution = iOutputResolution;


            if (docActiveView is IPageLayout)
            {
                //get the bounds of the "exportframe" of the active view.
                DisplayBounds = docActiveView.ExportFrame;
                //set up pGraphicsExtent, used if clipping to graphics extent.
                docGraphicsExtentEnv = GetGraphicsExtent(docActiveView);
            }
            else
            {
                //Get the bounds of the deviceframe for the screen.
                docDisplayTransformation = docActiveView.ScreenDisplay.DisplayTransformation;
                DisplayBounds            = docDisplayTransformation.get_DeviceFrame();
            }

            PixelBoundsEnv = new Envelope() as IEnvelope;

            if (bClipToGraphicsExtent && (docActiveView is IPageLayout))
            {
                docGraphicsExtentEnv = GetGraphicsExtent(docActiveView);
                docPageLayout        = docActiveView as PageLayout;
                pUnitConvertor       = new UnitConverter();

                //assign the x and y values representing the clipped area to the PixelBounds envelope
                PixelBoundsEnv.XMin = 0;
                PixelBoundsEnv.YMin = 0;
                PixelBoundsEnv.XMax = pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.XMax, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution - pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.XMin, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution;
                PixelBoundsEnv.YMax = pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.YMax, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution - pUnitConvertor.ConvertUnits(docGraphicsExtentEnv.YMin, docPageLayout.Page.Units, esriUnits.esriInches) * docExport.Resolution;

                //'assign the x and y values representing the clipped export extent to the exportRECT
                exportRECT.bottom = (int)(PixelBoundsEnv.YMax) + 1;
                exportRECT.left   = (int)(PixelBoundsEnv.XMin);
                exportRECT.top    = (int)(PixelBoundsEnv.YMin);
                exportRECT.right  = (int)(PixelBoundsEnv.XMax) + 1;

                //since we're clipping to graphics extent, set the visible bounds.
                docMapExtEnv = docGraphicsExtentEnv;
            }
            else
            {
                double tempratio  = iOutputResolution / iScreenResolution;
                double tempbottom = DisplayBounds.bottom * tempratio;
                double tempright  = DisplayBounds.right * tempratio;
                //'The values in the exportRECT tagRECT correspond to the width
                //and height to export, measured in pixels with an origin in the top left corner.
                exportRECT.bottom = (int)Math.Truncate(tempbottom);
                exportRECT.left   = 0;
                exportRECT.top    = 0;
                exportRECT.right  = (int)Math.Truncate(tempright);


                //populate the PixelBounds envelope with the values from exportRECT.
                // We need to do this because the exporter object requires an envelope object
                // instead of a tagRECT structure.
                PixelBoundsEnv.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);

                //since it's a page layout or an unclipped page layout we don't need docMapExtEnv.
                docMapExtEnv = null;
            }

            // Assign the envelope object to the exporter object's PixelBounds property.  The exporter object
            // will use these dimensions when allocating memory for the export file.
            docExport.PixelBounds = PixelBoundsEnv;

            // call the StartExporting method to tell docExport you're ready to start outputting.
            hdc = docExport.StartExporting();

            // Redraw the active view, rendering it to the exporter object device context instead of the app display.
            // We pass the following values:
            //  * hDC is the device context of the exporter object.
            //  * exportRECT is the tagRECT structure that describes the dimensions of the view that will be rendered.
            // The values in exportRECT should match those held in the exporter object's PixelBounds property.
            //  * docMapExtEnv is an envelope defining the section of the original image to draw into the export object.
            docActiveView.Output((int)hdc, (int)docExport.Resolution, ref exportRECT, docMapExtEnv, null);

            //finishexporting, then cleanup.
            docExport.FinishExporting();
            docExport.Cleanup();

            //MessageBox.Show("输出完成 " + sOutputName, "地图输出");

            //set the output quality back to the previous value
            SetOutputQuality(docActiveView, iPrevOutputImageQuality);
            if (bReenable)
            {
                /* reenable font smoothing if we disabled it before */
                EnableFontSmoothing();
                bReenable = false;
                if (!GetFontSmoothing())
                {
                    //error: cannot reenable font smoothing.
                    MessageBox.Show("Unable to reenable Font Smoothing", "Font Smoothing error");
                }
            }


            docMapExtEnv   = null;
            PixelBoundsEnv = null;
        }
Ejemplo n.º 42
0
        public void ExportActiveViewParameterized(IActiveView docActiveView, long iOutputResolution, long lResampleRatio, string ExportType, string sOutputName, Boolean bClipToGraphicsExtent)
        {
            /* EXPORT PARAMETER: (iOutputResolution) the resolution requested.
             * EXPORT PARAMETER: (lResampleRatio) Output Image Quality of the export.  The value here will only be used if the export
             * object is a format that allows setting of Output Image Quality, i.e. a vector exporter.
             * The value assigned to ResampleRatio should be in the range 1 to 5.
             * 1 corresponds to "Best", 5 corresponds to "Fast"
             * EXPORT PARAMETER: (ExportType) a string which contains the export type to create.
             * EXPORT PARAMETER: (sOutputDir) a string which contains the directory to output to.
             * EXPORT PARAMETER: (bClipToGraphicsExtent) Assign True or False to determine if export image will be clipped to the graphic
             * extent of layout elements.  This value is ignored for data view exports
             */

            /* Exports the Active View of the document to selected output format. */

            // using predefined static member
            IExport               docExport;
            IPrintAndExport       docPrintExport;
            IOutputRasterSettings RasterSettings;
            string sNameRoot;
            bool   bReenable = false;

            if (GetFontSmoothing())
            {
                /* font smoothing is on, disable it and set the flag to reenable it later. */
                bReenable = true;
                DisableFontSmoothing();
                if (GetFontSmoothing())
                {
                    //font smoothing is NOT successfully disabled, error out.
                    return;
                }
                //else font smoothing was successfully disabled.
            }

            // The Export*Class() type initializes a new export class of the desired type.
            if (ExportType == "PDF")
            {
                docExport = new ExportPDFClass();
            }
            else if (ExportType == "EPS")
            {
                docExport = new ExportPSClass();
            }
            else if (ExportType == "AI")
            {
                docExport = new ExportAIClass();
            }
            else if (ExportType == "BMP")
            {
                docExport = new ExportBMPClass();
            }
            else if (ExportType == "TIFF")
            {
                docExport = new ExportTIFFClass();
            }
            else if (ExportType == "SVG")
            {
                docExport = new ExportSVGClass();
            }
            else if (ExportType == "PNG")
            {
                docExport = new ExportPNGClass();
            }
            else if (ExportType == "GIF")
            {
                docExport = new ExportGIFClass();
            }
            else if (ExportType == "EMF")
            {
                docExport = new ExportEMFClass();
            }
            else if (ExportType == "JPEG")
            {
                docExport = new ExportJPEGClass();
            }
            else
            {
                MessageBox.Show("Unsupported export type " + ExportType + ", defaulting to EMF.");
                ExportType = "EMF";
                docExport  = new ExportEMFClass();
            }

            docPrintExport = new PrintAndExportClass();

            //set the name root for the export
            sNameRoot = "ExportActiveViewSampleOutput";

            //set the export filename (which is the nameroot + the appropriate file extension)
            //docExport.ExportFileName = sOutputDir + sNameRoot + "." + docExport.Filter.Split('.')[1].Split('|')[0].Split(')')[0];
            docExport.ExportFileName = sOutputName;

            //Output Image Quality of the export.  The value here will only be used if the export
            // object is a format that allows setting of Output Image Quality, i.e. a vector exporter.
            // The value assigned to ResampleRatio should be in the range 1 to 5.
            // 1 corresponds to "Best", 5 corresponds to "Fast"

            // check if export is vector or raster
            if (docExport is IOutputRasterSettings)
            {
                // for vector formats, assign the desired ResampleRatio to control drawing of raster layers at export time
                RasterSettings = (IOutputRasterSettings)docExport;
                RasterSettings.ResampleRatio = (int)lResampleRatio;

                // NOTE: for raster formats output quality of the DISPLAY is set to 1 for image export
                // formats by default which is what should be used
            }

            docPrintExport.Export(docActiveView, docExport, iOutputResolution, bClipToGraphicsExtent, null);

            //MessageBox.Show("Finished exporting " + sOutputDir + sNameRoot + "." + docExport.Filter.Split('.')[1].Split('|')[0].Split(')')[0] + ".", "Export Active View Sample");

            if (bReenable)
            {
                /* reenable font smoothing if we disabled it before */
                EnableFontSmoothing();
                bReenable = false;
                if (!GetFontSmoothing())
                {
                    //error: cannot reenable font smoothing.
                    MessageBox.Show("Unable to reenable Font Smoothing", "Font Smoothing error");
                }
            }
        }
Ejemplo n.º 43
0
        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();
        }
Ejemplo n.º 44
0
        /// <summary>Exports the page layout to a file.</summary>
        /// <param name="pageLayout">The page layout.</param>
        /// <param name="exportPath">The name of the output file.</param>
        /// <param name="exportFormat">The format of the output.</param>
        /// <param name="dpi">The resolution of the output files.</param>
        void ExportPageLayoutToFile(IPageLayout pageLayout, string exportPath, long dpi, ExportFormat exportFormat)
        {
            IExport export = null;

            // Get the color of the backgrounds for formats that support transparent backgrounds.
            IColor bgColor = null;
            switch (exportFormat)
            {
                case ExportFormat.GIF:
                case ExportFormat.PNG:
                    IPage page = pageLayout.Page;
                    bgColor = page.BackgroundColor;
                    break;
            }

            // Set "export" to the proper type of Export*Class, and set parameters specific to that image type.
            switch (exportFormat)
            {
                case ExportFormat.AI:
                    export = new ExportAIClass();
                    var ai = export as IExportAI2;
                    //ai.EmbedFonts = true;
                    break;
                case ExportFormat.EMF:
                    export = new ExportEMFClass();
                    var xEmf = export as IExportEMF;
                    //xEmf.Description =
                    break;
                case ExportFormat.PS:
                    export = new ExportPSClass();
                    var xPs = export as IExportPS;
                    xPs.EmbedFonts = true;
                    //xPs.Emulsion =
                    //xPs.Image =
                    //xPs.ImageCompression = esriExportImageCompression.esriExportImageCompressionNone
                    //xPs.LanguageLevel = esriExportPSLanguageLevel.esriExportPSLevel3
                    break;
                case ExportFormat.SVG:
                    export = new ExportSVGClass();
                    var xSvg = export as IExportSVG;
                    //xSvg.Compressed = true;
                    //xSvg.EmbedFonts = true;
                    break;
                case ExportFormat.PDF:
                    export = new ExportPDFClass();
                    var xPdf = export as IExportPDF;
                    //xPdf.Compressed = true;
                    //xPdf.EmbedFonts = true;
                    //xPdf.ImageCompression = esriExportImageCompression.esriExportImageCompressionNone
                    break;

                case ExportFormat.GIF:
                    export = new ExportGIFClass();
                    IExportGIF xGif = export as IExportGIF;
                    xGif.TransparentColor = bgColor;
                    //xGif.BiLevelThreshold =
                    //xGif.CompressionType = esriGIFCompression.esriGIFCompressionNone;
                    //xGif.InterlaceMode = false;
                    break;
                case ExportFormat.PNG:
                    export = new ExportPNGClass();
                    IExportPNG xPng = export as IExportPNG;
                    //xPng.BiLevelThreshold =
                    //xPng.InterlaceMode = false;
                    xPng.TransparentColor = bgColor;
                    break;
                case ExportFormat.BMP:
                    export = new ExportBMPClass();
                    IExportBMP xBmp = export as IExportBMP;
                    //xBmp.BiLevelThreshold =
                    //xBmp.RLECompression = true;
                    break;
                case ExportFormat.JPEG:
                    export = new ExportJPEGClass();
                    IExportJPEG xJpg = export as IExportJPEG;
                    //xJpg.ProgressiveMode = false;
                    //xJpg.Quality = 80;  //The JPEG compression / image quality. Range (0..100). Default is 100 (no compression / best quality).
                    break;
                case ExportFormat.TIFF:
                    export = new ExportTIFFClass();
                    IExportTIFF xTif = export as IExportTIFF;
                    //xTif.BiLevelThreshold =
                    //xTif.CompressionType =
                    //xTif.GeoTiff = true;
                    //The JPEG or Deflate (depending on the Compression type) compression / image quality. Range (0..100). Default is 100 (no compression / best quality).
                    //xTif.JPEGOrDeflateQuality = 100;
                    break;
                default:
                    const string MSG_FMT = "Support for \"{0}\" export is not yet implemented.";
                    string message = string.Format(MSG_FMT, Enum.GetName(typeof(ExportFormat), exportFormat));
                    throw new NotImplementedException(message);
            }

            IEnvelope pixelEnv = new EnvelopeClass();
            IEnvelope pageExt = GetPageExtent(pageLayout);
            IPoint upperRight = pageExt.UpperRight;
            pixelEnv.PutCoords(0, 0, dpi * upperRight.X, dpi * upperRight.Y);
            export.PixelBounds = pixelEnv;
            export.Resolution = dpi;
            export.ExportFileName = exportPath;
            //
            //(device coordinates origin is upper left, ypositive is down)
            tagRECT expRect;
            expRect.left = (int)export.PixelBounds.LowerLeft.X;
            expRect.bottom = (int)export.PixelBounds.UpperRight.Y;
            expRect.right = (int)export.PixelBounds.UpperRight.X;
            expRect.top = (int)export.PixelBounds.LowerLeft.Y;

            _app.StatusBar.set_Message(0, string.Format("exporting \"{0}\"", exportPath));
            long hdc = export.StartExporting();
            IActiveView av = (IActiveView)pageLayout;
            av.Output((int)hdc, (int)dpi, ref expRect, null, null);
            export.FinishExporting();
            export.Cleanup();
        }