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

///   <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 ;

        }

转载于:https://www.cnblogs.com/JinDin/archive/2008/08/28/1278943.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值