示例#1
0
        /// <summary>
        /// 输出图片
        /// </summary>
        /// <param name="pageLayout">页面布局对象</param>
        /// <param name="outPath">图片输出的完整路径,路径扩展名应为jpg,tiff,bmp,emf,png,gif,pdf,eps,ai,svg之一</param>
        /// <param name="resolution">图片分辨率(每英寸点数)</param>
        public static void ExportToPicture(this IPageLayout pageLayout, string outPath, double resolution = 300)
        {
            try
            {
                //参数检查
                IActiveView activeView = pageLayout as IActiveView;
                if (activeView == null)
                {
                    throw new Exception("输入参数(pageLayout)错误!");
                }

                IExport export = CreateExport(outPath, resolution);

                IEnvelope visibleBounds = new EnvelopeClass();
                visibleBounds.PutCoords(0, 0, pageLayout.Page.PrintableBounds.Width, pageLayout.Page.PrintableBounds.Height);

                //输出范围
                tagRECT pixelBounds = new tagRECT();
                pixelBounds.left   = pixelBounds.top = 0;
                pixelBounds.right  = (int)(export.Resolution / 2.54 * pageLayout.Page.PrintableBounds.Width);
                pixelBounds.bottom = (int)(export.Resolution / 2.54 * pageLayout.Page.PrintableBounds.Height);

                IEnvelope envelope = new EnvelopeClass();
                envelope.PutCoords(pixelBounds.left, pixelBounds.top, pixelBounds.right, pixelBounds.bottom);
                export.PixelBounds = envelope;

                //可用于取消操作
                ITrackCancel trackCancel = CreateTrackCancel();
                export.TrackCancel = trackCancel;

                //开始转出
                //activeView.Output(int hDC, int Dpi, ref tagRECT pixelBounds, ref IEnvelope VisibleBounds, ref ITrackCancel TrackCancel);
                //hDC - 输出设备
                //dpi - 每英寸点数(分辨率)。如果传递Null,则默认为hDC的分辨率。如果无法采样,则默认为窗口分辨率
                //pixelBounds - 以像素为单位指定的设备矩形
                //VisibleBounds - 缩放范围。如果传递Null,则默认为当前可见范围
                activeView.Output(export.StartExporting(), (int)export.Resolution, ref pixelBounds, visibleBounds, trackCancel);
                bool bContinue = trackCancel.Continue();

                //捕获是否继续
                if (bContinue)
                {
                    export.FinishExporting();
                    export.Cleanup();
                }
                else
                {
                    export.Cleanup();
                }
                trackCancel.Continue();
            }
            catch (Exception ex)
            {
                throw new Exception("输出图片出错:" + ex.Message);
            }
        }
示例#2
0
        public void Export(IExport pExport, string saveName)
        {
            IActiveView pActiveView;
            IEnvelope   pPixelBoundsEnv;
            int         iOutputResolution;
            int         iScreenResolution;
            int         hdc;

            pActiveView            = axMapControl.ActiveView;
            pExport.ExportFileName = saveName;
            iScreenResolution      = 96;
            iOutputResolution      = 300;
            pExport.Resolution     = iOutputResolution;

            tagRECT pExportFrame;

            pExportFrame = pActiveView.ExportFrame;
            tagRECT exportRECT;

            exportRECT.left   = 0;
            exportRECT.top    = 0;
            exportRECT.right  = pActiveView.ExportFrame.right * (iOutputResolution / iScreenResolution);
            exportRECT.bottom = pActiveView.ExportFrame.bottom * (iOutputResolution / iScreenResolution);

            pPixelBoundsEnv = new EnvelopeClass();
            pPixelBoundsEnv.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);

            pExport.PixelBounds = pPixelBoundsEnv;

            hdc = pExport.StartExporting();
            pActiveView.Output(hdc, (int)pExport.Resolution, ref exportRECT, null, null);
            pExport.FinishExporting();
            pExport.Cleanup();
        }
示例#3
0
 private void Export(IActiveView pActiveView)
 {
     try
     {
         tagRECT grect;
         IExport pExport    = this.m_pExport;
         int     num2       = 96;
         int     resolution = (int)pExport.Resolution;
         grect.left   = 0;
         grect.top    = 0;
         grect.right  = pActiveView.ExportFrame.right * (resolution / num2);
         grect.bottom = pActiveView.ExportFrame.bottom * (resolution / num2);
         IEnvelope envelope = new EnvelopeClass();
         envelope.PutCoords((double)grect.left, (double)grect.top, (double)grect.right, (double)grect.bottom);
         pExport.PixelBounds = envelope;
         int hDC = pExport.StartExporting();
         pActiveView.Output(hDC, (int)pExport.Resolution, ref grect, null, null);
         try
         {
             pExport.FinishExporting();
         }
         catch (Exception exception)
         {
             MessageBox.Show(exception.Message);
         }
         pExport.Cleanup();
     }
     catch
     {
     }
 }
        // ArcGIS Snippet Title:
        // Create JPEG from ActiveView
        //
        // Long Description:
        // Creates a .jpg (JPEG) file from IActiveView. Default values of 96 DPI are used for the image creation.
        //
        // Add the following references to the project:
        // ESRI.ArcGIS.Carto
        // ESRI.ArcGIS.Display
        // ESRI.ArcGIS.Geometry
        // ESRI.ArcGIS.Output
        // ESRI.ArcGIS.System
        //
        // Intended ArcGIS Products for this snippet:
        // ArcGIS Desktop (ArcEditor, ArcInfo, ArcView)
        // ArcGIS Engine
        // ArcGIS Server
        //
        // Applicable ArcGIS Product Versions:
        // 9.2
        // 9.3
        // 9.3.1
        // 10.0
        //
        // Required ArcGIS Extensions:
        // (NONE)
        //
        // Notes:
        // This snippet is intended to be inserted at the base level of a Class.
        // It is not intended to be nested within an existing Method.
        //

        ///<summary>Creates a .jpg (JPEG) file from IActiveView. Default values of 96 DPI are used for the image creation.</summary>
        ///
        ///<param name="activeView">An IActiveView interface</param>
        ///<param name="pathFileName">A System.String that the path and filename of the JPEG you want to create. Example: "C:\temp\test.jpg"</param>
        ///
        ///<returns>A System.Boolean indicating the success</returns>
        ///
        ///<remarks></remarks>
        public System.Boolean CreateJPEGFromActiveView(ESRI.ArcGIS.Carto.IActiveView activeView, System.String pathFileName)
        {
            //parameter check
            if (activeView == null || !(pathFileName.EndsWith(".jpg")))
            {
                return(false);
            }
            IExport export = (IExport) new ExportJPEG();

            export.ExportFileName = pathFileName;

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

            ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
            envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
            export.PixelBounds = envelope;
            System.Int32 hDC = export.StartExporting();
            activeView.Output(hDC, (System.Int16)export.Resolution, ref exportRECT, null, null);

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

            return(true);
        }
        private void btnPrint_Click(object sender, EventArgs e)
        {
            this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
            if (export is IOutputRasterSettings)
            {
                //矢量格式输出
                rasterSettings = (IOutputRasterSettings)export;
                rasterSettings.ResampleRatio = 1;
            }
            if (Information.IsNumeric(txtResolution.Text))
            {
                iOutputResolution = Convert.ToInt32(txtResolution.Text);
            }
            else
            {
                iOutputResolution = 300;
            }

            IActiveView pActiveView       = axPageLayoutControl1.ActiveView;
            double      iScreenResolution = pActiveView.ScreenDisplay.DisplayTransformation.Resolution;
            tagRECT     exportRECT;

            exportRECT.left   = 0;
            exportRECT.top    = 0;
            exportRECT.right  = Convert.ToInt32(Math.Ceiling(pActiveView.ExportFrame.right * (iOutputResolution / iScreenResolution)));
            exportRECT.bottom = Convert.ToInt32(Math.Round(pActiveView.ExportFrame.bottom * (iOutputResolution / iScreenResolution)));
            IEnvelope pPixelBoundsEnv = new EnvelopeClass();

            pPixelBoundsEnv.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
            export.Resolution     = iOutputResolution;
            export.PixelBounds    = pPixelBoundsEnv;
            export.ExportFileName = exportFileName;
            int hDC = export.StartExporting();

            pActiveView.Output(hDC, (int)export.Resolution, ref exportRECT, null, null);
            export.FinishExporting();
            export.Cleanup();
            this.Close();
            this.Cursor = Cursors.Default;
            MessageBox.Show("输出成功!", "消息提示:", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
示例#6
0
        private void btnPrint_Click(object sender, EventArgs e)
        {
            if (export is IOutputRasterSettings)
            {
                rasterSettings = export as IOutputRasterSettings;
                rasterSettings.ResampleRatio = 1;
            }
            if (Information.IsNumeric(txtResolution.Text))
            {
                iOutputResolution = Convert.ToInt32(txtResolution.Text);
            }
            else
            {
                iOutputResolution = 300;
            }
            IActiveView pActiveView       = axPageLayoutControl1.ActiveView;
            double      iScreenResolution = pActiveView.ScreenDisplay.
                                            DisplayTransformation.Resolution;
            tagRECT exportRECT; exportRECT.left = 0; exportRECT.top = 0;

            exportRECT.right = Convert.ToInt32(Math.Ceiling(pActiveView.ExportFrame.
                                                            right * (iOutputResolution / iScreenResolution)));
            exportRECT.bottom = Convert.ToInt32(Math.Round(pActiveView.ExportFrame.
                                                           bottom * (iOutputResolution / iScreenResolution)));
            IEnvelope pPixelBoundsEnv = new Envelope() as IEnvelope;

            pPixelBoundsEnv.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right
                                      , exportRECT.bottom);
            export.Resolution     = iOutputResolution;
            export.PixelBounds    = pPixelBoundsEnv;
            export.ExportFileName = exportFileName;
            int hDC = export.StartExporting();

            pActiveView.Output(hDC, (int)export.Resolution, ref exportRECT,
                               null, null);
            export.FinishExporting();
            export.Cleanup();
            MessageBox.Show("Export Success");
        }
示例#7
0
        /// <summary>
        /// 输出图片
        /// </summary>
        /// <param name="activeView"></param>
        /// <param name="outPath">图片输出的完整路径,路径扩展名应为jpg,tiff,bmp,emf,png,gif,pdf,eps,ai,svg之一</param>
        /// <param name="resolution">图片分辨率(每英寸点数)</param>
        /// <returns></returns>
        public static bool ExportToPicture(this IActiveView activeView, string outPath, double resolution = 300)
        {
            IExport export     = CreateExport(outPath, resolution);
            tagRECT exportRECT = activeView.ExportFrame;

            export.PixelBounds = new EnvelopeClass
            {
                XMin = exportRECT.left,
                YMin = exportRECT.top,
                XMax = exportRECT.right,
                YMax = exportRECT.bottom
            };

            //activeView.Output(int hDC, int dpi, ref tagRECT pixelBounds, ref IEnvelope visibleBounds, ref ITrackCancel trackCancel);
            //hDC - 输出设备
            //dpi - 每英寸点数(分辨率)。如果为0,则默认为hDC的分辨率。如果无法采样,则默认为窗口分辨率
            //pixelBounds - 以像素为单位指定的设备矩形
            //VisibleBounds - 缩放范围。如果传递Null,则默认为当前可见范围
            //如果要将数据框绘制到640x480位图,请指定以下参数值:
            //  dpi - 0
            //  pixelBounds - { 0, 0, 640, 480 }
            //  visible bounds -0
            //如果要创建在300 DPI打印机上打印8.5 x 11的位图,请指定以下参数值:
            //  dpi - 300
            //  pixel bounds - { 0, 0, 8.5 * dpi, 11 * dpi }
            //  visible bounds -0
            //如果要缩放到某个位置并在300x300位图上绘制,请指定以下参数值:
            //  dpi - 0
            //  pixel bounds - { 0, 0, 300, 300 }
            //  visible bounds -  { -45.0, 44.0, -44.0, 45.0 }
            activeView.Output(export.StartExporting(), (int)export.Resolution, ref exportRECT, null, null);

            export.FinishExporting();
            export.Cleanup();
            return(true);
        }
示例#8
0
        /// <summary>
        /// 写入当前切片级别地理坐标系切片
        /// </summary>
        /// <param name="i"></param>
        /// <param name="tileFileInfo"></param>
        /// <param name="outPutDir"></param>
        public static void WriteGeoLevel(int i, TileFileInfo tileFileInfo, string outPutDir)
        {
            IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactory();
            IWorkspace        pWs           = workspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(tileFileInfo.filePath), 0);
            IFeatureClass     pFeatureClass = (pWs as IFeatureWorkspace).OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(tileFileInfo.filePath));
            IFeatureLayer     featureLayer  = new FeatureLayerClass
            {
                FeatureClass = pFeatureClass
            };
            IDataset dataSet = (IDataset)pFeatureClass;

            featureLayer.Name = dataSet.Name;
            IMap map = new MapClass();

            map.AddLayer(featureLayer);

            IMapControlDefault pMapControl = new MapControlClass();

            pMapControl.Map = map;
            IActiveView pActiveView = pMapControl.ActiveView;

            tagRECT rect = new tagRECT();

            rect.left   = rect.top = 0;
            rect.right  = 256;
            rect.bottom = 256;
            IExport pExport = null;

            IEnvelope pEnvelope = new EnvelopeClass();
            string    temp      = i.ToString();

            if (temp.Length < 2)
            {
                temp = "0" + temp;
            }
            System.IO.DirectoryInfo LevelDir = new System.IO.DirectoryInfo(outPutDir).CreateSubdirectory($"L{temp}");
            pMapControl.MapScale = TileParam.TileParamProjCoordinateSystem.TileScales[i];
            pMapControl.Refresh();
            Console.WriteLine($"Level:L{temp}:分辨率{TileParam.TileParamGeoCoordinateSystem.TileResolutions[i]}");
            double imageHeighy = TileParam.TileParamGeoCoordinateSystem.TileResolutions[i] * TileParam.TileParamGeoCoordinateSystem.TileSize;

            for (int dy = 1, iRnum = 0; TileParam.TileOriginGeo.OriginY - imageHeighy * dy > tileFileInfo.MinY - imageHeighy; dy++, iRnum++)
            {
                if (TileParam.TileOriginGeo.OriginY - imageHeighy * dy > tileFileInfo.MaxY)
                {
                    continue;
                }
                string tmpy = iRnum.ToString("X");
                while (tmpy.Length < 8)
                {
                    tmpy = "0" + tmpy;
                }
                Console.WriteLine($"--行号:R{tmpy}");
                System.IO.DirectoryInfo RowDir = LevelDir.CreateSubdirectory($"R{tmpy}");

                for (int dx = 1, iCnum = 0; TileParam.TileOriginGeo.OriginX + imageHeighy * dx < tileFileInfo.MaxX + imageHeighy; dx++, iCnum++)
                {
                    if (TileParam.TileOriginGeo.OriginX + imageHeighy * dx < tileFileInfo.MinX)
                    {
                        continue;
                    }
                    string tmpx = iCnum.ToString("X");
                    while (tmpx.Length < 8)
                    {
                        tmpx = "0" + tmpx;
                    }
                    try
                    {
                        pEnvelope.PutCoords(TileParam.TileOriginGeo.OriginX + imageHeighy * (dx - 1), TileParam.TileOriginGeo.OriginY - imageHeighy * dy, TileParam.TileOriginGeo.OriginX + imageHeighy * dx, TileParam.TileOriginGeo.OriginY - imageHeighy * (dy - 1));
                        pExport = ToExporter("PNG");
                        pExport.ExportFileName = RowDir.FullName + "\\C" + tmpx + ".png";
                        Console.WriteLine($"----列号:C{tmpx}    {pExport.ExportFileName}");
                        pExport.Resolution = 96;
                        IEnvelope pPixelBoundsEnv = new EnvelopeClass();
                        pPixelBoundsEnv.PutCoords(rect.left, rect.top, rect.right, rect.bottom);
                        pExport.PixelBounds = pPixelBoundsEnv;
                        //开始导出,获取DC
                        int hDC = pExport.StartExporting();
                        //导出
                        pActiveView.Output(hDC, 96, ref rect, pEnvelope, null);
                        //结束导出
                        pExport.FinishExporting();
                        //清理导出类
                        pExport.Cleanup();
                        RealeaseAO(pExport);
                        RealeaseAO(pPixelBoundsEnv);
                    }
                    catch (Exception ex) { Helpers.ErrorHelper.PrintException(ex); }
                }
            }
            RealeaseAO(workspaceFactory);
            RealeaseAO(pWs);
            RealeaseAO(pFeatureClass);
            RealeaseAO(featureLayer);
            RealeaseAO(map);
            RealeaseAO(pMapControl);
        }
        //使用IActiveView.Output方法输出
        //Width和Hight用于设置输出的图片尺寸,默认为0则使用ActiveView.ExportFrame
        //VisibleBounds用于设置待输出的地图范围,默认为null则使用ActiveView.Extent
        private void ActiveViewOutput(IActiveView docActiveView, int iOutputResolution, int Width, int Height, IEnvelope VisibleBounds, string sExportFileName, IExport docExport)
        {
            docExport.ExportFileName = sExportFileName;
            if (iOutputResolution <= 0) iOutputResolution = 96;
            if (Width <= 0 || Height <= 0)
            {
            Width = docActiveView.ExportFrame.right;
            Height = docActiveView.ExportFrame.bottom;
            if (Width == 0)
                Width = 1024;
            if (Height == 0)
                Height = 768;
            Width = (Width * iOutputResolution) / 96;
            Height = (Height * iOutputResolution) / 96;
            }
            docExport.Resolution = iOutputResolution;
            ESRI.ArcGIS.esriSystem.tagRECT exportRECT = new ESRI.ArcGIS.esriSystem.tagRECT();
            exportRECT.left = 0;
            exportRECT.top = 0;
            exportRECT.right = Width;
            exportRECT.bottom = Height;

            IEnvelope envelope = new EnvelopeClass();
            envelope.PutCoords(exportRECT.left, exportRECT.top, exportRECT.right, exportRECT.bottom);
            docExport.PixelBounds = envelope;

            System.Int32 hDC = docExport.StartExporting();
            docActiveView.Output(hDC, iOutputResolution, ref exportRECT, VisibleBounds, null);
            docExport.FinishExporting();
            docExport.Cleanup();
        }
示例#10
0
        /// <summary>
        /// 打印或者输出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPrint_Click(object sender, EventArgs e)
        {
            if (axPageLayoutControl1.ActiveView.FocusMap.LayerCount == 0)
            {
                MessageBox.Show("No Map !");
                return;
            }
            if (rdoPrint.Checked)
            {
                printDialog1.AllowSomePages = true; //允许用户选择打印哪些页面
                printDialog1.ShowHelp       = true;
                printDialog1.Document       = document;
                DialogResult result = printDialog1.ShowDialog();
                if (result == DialogResult.OK)
                {
                    document.Print();
                }
            }
            if (rdoOutput.Checked)
            {
                IExport export = null;
                string  path   = outputPath.Text;
                if (path == "无")
                {
                    MessageBox.Show("请先选择导出路径");
                    return;
                }
                export = getExportClass(path);
                if (export == null)
                {
                    MessageBox.Show("导出路径错误");
                    return;
                }
                export.ExportFileName = path;
                IEnvelope pEnvelope = axPageLayoutControl1.Extent;

                //导出参数
                export.Resolution = 300;
                tagRECT exportRect = new tagRECT();
                exportRect.left = 0;
                exportRect.top  = 0;
                //这里暂时固定大小
                exportRect.right  = 1000;
                exportRect.bottom = 1300;
                IEnvelope envelope = new EnvelopeClass();
                //输出范围
                envelope.PutCoords(exportRect.left, exportRect.bottom, exportRect.right, exportRect.top);
                export.PixelBounds = envelope;
                //可用于取消操作
                ITrackCancel pCancel = new CancelTrackerClass();
                export.TrackCancel = pCancel;
                pCancel.Reset();
                //点击ESC键时,中止转出
                pCancel.CancelOnKeyPress = true;
                pCancel.CancelOnClick    = false;
                pCancel.ProcessMessages  = true;
                //获取handle
                int hDC = export.StartExporting();
                //开始转出
                axPageLayoutControl1.ActiveView.Output(hDC, (int)export.Resolution, ref exportRect, pEnvelope, pCancel);
                bool bContinue = pCancel.Continue();
                //捕获是否继续
                if (bContinue)
                {
                    export.FinishExporting();
                    export.Cleanup();
                    MessageBox.Show("导出至" + path);
                }
                else
                {
                    export.Cleanup();
                }
                bContinue = pCancel.Continue();
            }
        }