Esempio n. 1
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);
        }
Esempio n. 2
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);
            }
        }
        //输出当前地图为图片
        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;

            }
        }
Esempio n. 4
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;
            }
        }
Esempio n. 5
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");
        }
      }
    }
Esempio n. 7
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");
                }
            }
        }
        /// <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();
        }
 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;
 }
Esempio n. 10
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();
        }
Esempio n. 11
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();
        }
Esempio n. 12
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");
            }
        }
Esempio n. 13
0
        private void ExportActiveViewParameterized(long iOutputResolution, long lResampleRatio, string ExportType,
                                                   string sOutputDir, string sNameRoot, Boolean bClipToGraphicsExtent, AxPageLayoutControl pageLayoutControl)
        {
            //解决文件名错误
            sNameRoot = sNameRoot.Substring(1, sNameRoot.Length - 1);
            IActiveView            docActiveView = pageLayoutControl.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())
            {
                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("!!不支持的格式 " + ExportType + ", 默认导出 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 = "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];


            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 = 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(
                "成功导出地图: " + sOutputDir + sNameRoot + "." + docExport.Filter.Split('.')[1].Split('|')[0].Split(')')[0] +
                ".", "提示");
            //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;
        }
Esempio n. 14
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (System.IO.File.Exists(textBoxFileName.Text.ToString()) == true)
            {
                MessageBox.Show("该文件已经存在,请重新命名!");
                textBoxFileName.SelectAll();
            }
            else
            {
                IExport            pExport    = null;
                IWorldFileSettings pWorldFile = null;
                IExportImage       pExportType;
                IEnvelope          pDriverBounds = null;

                ESRI.ArcGIS.esriSystem.tagRECT userRECT = new ESRI.ArcGIS.esriSystem.tagRECT();
                IEnvelope pEnv = new EnvelopeClass();

                string   FilePath    = this.m_strFileName;
                string[] strFileName = FilePath.Split('.');
                string   strFileType = strFileName[1];
                switch (strFileType)
                {
                case "jpg":
                    pExport = new ExportJPEGClass();
                    break;

                case "bmp":
                    pExport = new ExportBMPClass();
                    break;

                case "gif":
                    pExport = new ExportGIFClass();
                    break;

                case "tif":
                    pExport = new ExportTIFFClass();
                    break;

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

                case "emf":
                    pExport = new ExportEMFClass();
                    break;

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

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

                case "svg":
                    pExport = new ExportSVGClass();
                    break;

                default:
                    pExport = new ExportJPEGClass();
                    break;
                }

                pExport.ExportFileName = this.m_strFileName;
                pExport.Resolution     = Convert.ToInt32(numUDresolution.Value);
                pExportType            = pExport as IExportImage;
                pExportType.ImageType  = esriExportImageType.esriExportImageTypeTrueColor;
                pEnv                       = m_pageLayoutControl.ActiveView.Extent;
                pWorldFile                 = (IWorldFileSettings)pExport;
                pWorldFile.MapExtent       = pEnv;
                pWorldFile.OutputWorldFile = false;
                userRECT.top               = 0;
                userRECT.left              = 0;
                userRECT.right             = Convert.ToInt32(txtBoxWidth.Text);
                userRECT.bottom            = Convert.ToInt32(txtBoxHeight.Text);
                pDriverBounds              = new EnvelopeClass();
                pDriverBounds.PutCoords(userRECT.top, userRECT.bottom, userRECT.right, userRECT.top);
                pExport.PixelBounds = pDriverBounds;
                ITrackCancel pTrackCancel = new TrackCancelClass();
                m_pageLayoutControl.ActiveView.Output(pExport.StartExporting(), Convert.ToInt32(numUDresolution.Value), ref userRECT, m_pageLayoutControl.ActiveView.Extent, pTrackCancel);
                pExport.FinishExporting();
                MessageBox.Show("打印图片保存成功!", "保存", MessageBoxButtons.OK);
                this.Close();
            }
        }
Esempio n. 15
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);
        }
Esempio n. 16
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;
        }
Esempio n. 17
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;
        }
Esempio n. 18
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);
            }
        }