cl991036
管理员
管理员
  • 注册日期2003-07-25
  • 发帖数5913
  • QQ14265545
  • 铜币29656枚
  • 威望213点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • GIS帝国铁杆
阅读:1971回复:4

C#+ArcEngine 自定义范围输出为栅格图像(JPG/BMP)

楼主#
更多 发布于:2008-09-09 09:39
/// <summary><BR>        /// 打印输出.该功能目前测试只适用于JPEG,BMP.格式<BR>        /// </summary><BR>        /// <param name="pExport"></param><BR>        /// <param name="dResolution">分辨率</param><BR>        /// <param name="outputPath">输出路径</param><BR>        /// <param name="pVisibleBounds">自定义可见区域</param><BR>        private void FunExportImage(IExport pExport, double dResolution, string outputPath,IEnvelope pVisibleBounds)<BR>        {<BR>            IEnvelope pPixelBounds;<BR>            ESRI.ArcGIS.Display.tagRECT outtagRECT;<BR>            ESRI.ArcGIS.Display.tagRECT DisplayBounds = m_ActiveView.ExportFrame;<BR>            double iScreenResolution;<BR>            if (pExport == null)<BR>            {<BR>                MessageBox.Show("打印类型未指定");<BR>                return;<BR>            }<BR><BR>            if(pVisibleBounds!=null) //自定义框范围<BR>            {<BR>                IDisplayTransformation pDisplayTransformation = m_ActiveView.ScreenDisplay.DisplayTransformation;<BR>                pDisplayTransformation.TransformRect(pVisibleBounds, ref DisplayBounds, 8);//8代表esriDisplayTransformEnum.esriTransformToDevice<BR>            }<BR><BR>            if (pExport is IExportImage)<BR>            {<BR>                IExportImage pExportImage = pExport as IExportImage;<BR>                pExportImage.ImageType = esriExportImageType.esriExportImageTypeTrueColor;<BR>            }<BR><BR>            iScreenResolution = m_ActiveView.ScreenDisplay.DisplayTransformation.Resolution;<BR>                      <BR>            double l_resolution = Convert.ToDouble(domainResolution.Value);<BR><BR>            //=====================================================================<BR>            //<BR>            //方法一<BR>            //<BR>            //一厘米包含37.79524个像素<BR>            //double dPixel = 37.79524;<BR>            ////按照设置输入分辨率计算一厘米所含的像素数<BR>            //double tempratio = l_resolution * dPixel / iScreenResolution;<BR>            ////输出图形的高度<BR>            //double tempbottom = (DisplayBounds.bottom - DisplayBounds.top) * tempratio;<BR>            ////输出图形的宽度<BR>            //double tempright = (DisplayBounds.right - DisplayBounds.left) * tempratio + 0.1 * tempratio;<BR>            //======================================================================<BR>            //<BR>            //方法二:暂时可行.<BR>            //<BR>            double tempratio = l_resolution / iScreenResolution;<BR>            double tempbottom = (DisplayBounds.bottom - DisplayBounds.top) * tempratio;<BR>            double tempright = (DisplayBounds.right - DisplayBounds.left) * tempratio;<BR>            //=====================================================================<BR>            outtagRECT.left = 0;<BR>            outtagRECT.top = 0;<BR>            outtagRECT.bottom = Convert.ToInt32(Math.Truncate(tempbottom));<BR>            outtagRECT.right = Convert.ToInt32(Math.Truncate(tempright));<BR><BR>            pPixelBounds = new EnvelopeClass();<BR>            pPixelBounds.PutCoords(outtagRECT.left, outtagRECT.top, outtagRECT.right, outtagRECT.bottom);<BR><BR>            pExport.Resolution = dResolution;<BR>            pExport.PixelBounds = pPixelBounds;<BR>            pExport.ExportFileName = outputPath;<BR><BR>            try<BR>            {<BR>                ITrackCancel pTrackCancel = new TrackCancelClass();<BR>                int hDC;<BR>                hDC = pExport.StartExporting();<BR><BR>                if (m_frmProBar == null) //m_frmProBar为进度条窗体<BR>                    FunProgressBar();<BR>                m_frmProBar.Show();<BR><BR>                m_ActiveView.Output(hDC, (int)dResolution, ref outtagRECT, pVisibleBounds, pTrackCancel);<BR>                pExport.FinishExporting();<BR><BR>                m_frmProBar.Hide();<BR><BR>                if (DialogResult.Yes == MessageBox.Show("出图成功! \n图片保存在" + txtOutPutPath.Text+"\n是否需要打开文件所在的目录?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Information))<BR>                {<BR>                    System.Diagnostics.Process.Start("explorer.exe", txtOutPutPath.Text); <BR>                }<BR>                pExport.Cleanup();<BR>            }<BR>            catch<BR>            {<BR>                MessageBox.Show("出图失败!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning);<BR>                //释放变量<BR>                m_frmProBar = null;<BR>                pExport = null;<BR>                pVisibleBounds = null;<BR>            }<BR>            //释放变量<BR>            pExport = null;<BR>            pVisibleBounds = null;<BR><BR>        }
喜欢0 评分0
没钱又丑,农村户口。头可断,发型一定不能乱。 邮箱:gisempire@qq.com
水木
路人甲
路人甲
  • 注册日期2007-10-01
  • 发帖数17
  • QQ
  • 铜币171枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2008-09-13 00:13
这么好的帖子怎么没人顶?<img src="images/post/smile/dvbbs/em02.gif" />
举报 回复(0) 喜欢(0)     评分
mingkof
路人甲
路人甲
  • 注册日期2006-01-01
  • 发帖数73
  • QQ
  • 铜币408枚
  • 威望0点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2008-09-16 17:24
<P>很好</P><img src="images/post/smile/dvbbs/em01.gif" />
举报 回复(0) 喜欢(0)     评分
风雪无痕
路人甲
路人甲
  • 注册日期2007-08-15
  • 发帖数21
  • QQ
  • 铜币161枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2008-09-18 18:16
<P>好好</P>
举报 回复(0) 喜欢(0)     评分
niehoude
路人甲
路人甲
  • 注册日期2008-12-12
  • 发帖数5
  • QQ
  • 铜币132枚
  • 威望0点
  • 贡献值0点
  • 银元0个
4楼#
发布于:2009-06-25 11:42
<P><img src="images/post/smile/dvbbs/em01.gif" /></P>
<P>8错!</P>
举报 回复(0) 喜欢(0)     评分
游客

返回顶部