C#+ArcEngine 自訂範圍輸出為柵格映像(JPG/BMP)

來源:互聯網
上載者:User
/// <summary>
        /// 列印輸出.該功能目前測試只適用於JPEG,BMP.格式
        /// </summary>
        /// <param name="pExport"></param>
        /// <param name="dResolution">解析度</param>
        /// <param name="outputPath">輸出路徑</param>
        /// <param name="pVisibleBounds">自訂可見地區</param>
        private void FunExportImage(IExport pExport, double dResolution, string outputPath,IEnvelope pVisibleBounds)
        {
            IEnvelope pPixelBounds;
            ESRI.ArcGIS.Display.tagRECT outtagRECT;
            ESRI.ArcGIS.Display.tagRECT DisplayBounds = m_ActiveView.ExportFrame;
            double iScreenResolution;
            if (pExport == null)
            {
                MessageBox.Show("列印類型未指定");
                return;
            }

            if(pVisibleBounds!=null) //自訂框範圍
            {
                IDisplayTransformation pDisplayTransformation = m_ActiveView.ScreenDisplay.DisplayTransformation;
                pDisplayTransformation.TransformRect(pVisibleBounds, ref DisplayBounds, 8);//8代表esriDisplayTransformEnum.esriTransformToDevice
            }

            if (pExport is IExportImage)
            {
                IExportImage pExportImage = pExport as IExportImage;
                pExportImage.ImageType = esriExportImageType.esriExportImageTypeTrueColor;
            }

            iScreenResolution = m_ActiveView.ScreenDisplay.DisplayTransformation.Resolution;
                      
            double l_resolution = Convert.ToDouble(domainResolution.Value);

            //=====================================================================
            //
            //方法一
            //
            //一厘米包含37.79524個像素
            //double dPixel = 37.79524;
            ////按照設定輸入解析度計算一厘米所含的像素數
            //double tempratio = l_resolution * dPixel / iScreenResolution;
            ////輸出圖形的高度
            //double tempbottom = (DisplayBounds.bottom - DisplayBounds.top) * tempratio;
            ////輸出圖形的寬度
            //double tempright = (DisplayBounds.right - DisplayBounds.left) * tempratio + 0.1 * tempratio;
            //======================================================================
            //
            //方法二:暫時可行.
            //
            double tempratio = l_resolution / iScreenResolution;
            double tempbottom = (DisplayBounds.bottom - DisplayBounds.top) * tempratio;
            double tempright = (DisplayBounds.right - DisplayBounds.left) * tempratio;
            //=====================================================================
            outtagRECT.left = 0;
            outtagRECT.top = 0;
            outtagRECT.bottom = Convert.ToInt32(Math.Truncate(tempbottom));
            outtagRECT.right = Convert.ToInt32(Math.Truncate(tempright));

            pPixelBounds = new EnvelopeClass();
            pPixelBounds.PutCoords(outtagRECT.left, outtagRECT.top, outtagRECT.right, outtagRECT.bottom);

            pExport.Resolution = dResolution;
            pExport.PixelBounds = pPixelBounds;
            pExport.ExportFileName = outputPath;

            try
            {
                ITrackCancel pTrackCancel = new TrackCancelClass();
                int hDC;
                hDC = pExport.StartExporting();

                if (m_frmProBar == null) //m_frmProBar為進度條表單
                    FunProgressBar();
                m_frmProBar.Show();

                m_ActiveView.Output(hDC, (int)dResolution, ref outtagRECT, pVisibleBounds, pTrackCancel);
                pExport.FinishExporting();

                m_frmProBar.Hide();

                if (DialogResult.Yes == MessageBox.Show("出圖成功! \n圖片儲存在" + txtOutPutPath.Text+"\n是否需要開啟檔案所在的目錄?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information))
                {
                    System.Diagnostics.Process.Start("explorer.exe", txtOutPutPath.Text); 
                }
                pExport.Cleanup();
            }
            catch
            {
                MessageBox.Show("出圖失敗!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);
                //釋放變數
                m_frmProBar = null;
                pExport = null;
                pVisibleBounds = null;
            }
            //釋放變數
            pExport = null;
            pVisibleBounds = null;

        }

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.