阅读:1971回复:4
C#+ArcEngine 自定义范围输出为栅格图像(JPG/BMP)
/// <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> }
|
|
|
1楼#
发布于:2008-09-13 00:13
这么好的帖子怎么没人顶?<img src="images/post/smile/dvbbs/em02.gif" />
|
|
2楼#
发布于:2008-09-16 17:24
<P>很好</P><img src="images/post/smile/dvbbs/em01.gif" />
|
|
3楼#
发布于:2008-09-18 18:16
<P>好好</P>
|
|
4楼#
发布于:2009-06-25 11:42
<P><img src="images/post/smile/dvbbs/em01.gif" /></P>
<P>8错!</P> |
|