Arcengine, C#,输出栅格图片的简单方法

///

        /// 地图输出栅格图片的简单方法,返回输出的文件名by yl [email protected]

        ///

        ///

        ///

        public  static string  ExportImage(IActiveView pActiveView)

        {

 

            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.left = 0;

            ptagRECT.top = 0;

            ptagRECT.right = (int)pActiveView.Extent.Width;

            ptagRECT.bottom = (int)pActiveView.Extent.Height;

 

            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;

        }

 

你可能感兴趣的:(C#,ArcObjects)