日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

ArcGIS Engine開發系列:將地圖導出為圖片的兩

系統 2333 0

??? 在ArcGIS的開發中,我們經常需要將當前地圖打印(或是轉出)到圖片文件中。將Map或Layout中的圖象轉出有兩種方法,一種為通過
IActiveView的OutPut函數,另外一種是通過IExport接口來實現。第一種方法導出速度較快,實現也比較方便,但該方法對于圖片的行或
列數超過10000左右時,導出經常會失敗(具體原因未知),第二種方法導出速度較慢,但效果較好,且可以在導出過程中通過ITrackCancel來中
止導出操作。
????? 通過IActiveView的方式導出是通過創建Graphics對象來實現,具體示例代碼如下:

Java代碼 復制代碼
  1. ///?<summary> ??
  2. ??
  3. ///?將Map上指定范圍(該范圍為規則區域)內的內容輸出到Image,注意,當圖片的行數或列數超過10000左右時,出現原因示知的失敗 ??
  4. ??
  5. ///?</summary> ??
  6. ??
  7. ///?<param?name="pMap">需轉出的MAP</param> ??
  8. ///?<param?name="outRect">輸出的圖片大小</param> ??
  9. ///?<param?name="pEnvelope">指定的輸出范圍(為Envelope類型)</param> ??
  10. ///?<returns>輸出的Image?具體需要保存為什么格式,可通過Image對象來實現</returns> ??
  11. public ? static ?Image?SaveCurrentToImage(IMap?pMap,?Size?outRect,?IEnvelope?pEnvelope) ??
  12. ?{ ??
  13. ?????? //賦值 ??
  14. ??????tagRECT?rect?=? new ?tagRECT(); ??
  15. ??????rect.left?=?rect.top?=? 0 ; ??
  16. ??????rect.right?=?outRect.Width; ??
  17. ??????rect.bottom?=?outRect.Height; ??
  18. ?????? try ??
  19. ??????{???????????????? ??
  20. ?????????? //轉換成activeView,若為ILayout,則將Layout轉換為IActiveView ??
  21. ??????????IActiveView?pActiveView?=?(IActiveView)pMap; ??
  22. ?????????? //?創建圖像,為24位色 ??
  23. ??????????Image?image?=? new ?Bitmap(outRect.Width,?outRect.Height);? //,?System.Drawing.Imaging.PixelFormat.Format24bppRgb); ??
  24. ??????????System.Drawing.Graphics?g?=?System.Drawing.Graphics.FromImage(image); ??
  25. ??
  26. ?????????? //?填充背景色(白色) ??
  27. ??????????g.FillRectangle(Brushes.White,? 0 ,? 0 ,?outRect.Width,?outRect.Height); ??
  28. ??
  29. ?????????? int ?dpi?=?( int )(outRect.Width?/?pEnvelope.Width); ??
  30. ??
  31. ??????????pActiveView.Output(g.GetHdc().ToInt32(),?dpi,?ref?rect,?pEnvelope,? null ); ??
  32. ??
  33. ??????????g.ReleaseHdc();???????????? ??
  34. ??
  35. ?????????? return ?image; ??
  36. ?????} ??
  37. ??
  38. ????? catch ?(Exception?excp) ??
  39. ?????{ ??
  40. ????????MessageBox.Show(excp.Message?+? "將當前地圖轉出出錯,原因未知" ,? "出錯提示" ,?MessageBoxButtons.OK,?MessageBoxIcon.Error); ??
  41. ??
  42. ?????????? return ? null ; ??
  43. ??????} ??
  44. ?}??
    /// <summary>

/// 將Map上指定范圍(該范圍為規則區域)內的內容輸出到Image,注意,當圖片的行數或列數超過10000左右時,出現原因示知的失敗

/// </summary>

/// <param name="pMap">需轉出的MAP</param>
/// <param name="outRect">輸出的圖片大小</param>
/// <param name="pEnvelope">指定的輸出范圍(為Envelope類型)</param>
/// <returns>輸出的Image 具體需要保存為什么格式,可通過Image對象來實現</returns>
public static Image SaveCurrentToImage(IMap pMap, Size outRect, IEnvelope pEnvelope)
 {
      //賦值
      tagRECT rect = new tagRECT();
      rect.left = rect.top = 0;
      rect.right = outRect.Width;
      rect.bottom = outRect.Height;
      try
      {                
          //轉換成activeView,若為ILayout,則將Layout轉換為IActiveView
          IActiveView pActiveView = (IActiveView)pMap;
          // 創建圖像,為24位色
          Image image = new Bitmap(outRect.Width, outRect.Height); //, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
          System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image);

          // 填充背景色(白色)
          g.FillRectangle(Brushes.White, 0, 0, outRect.Width, outRect.Height);

          int dpi = (int)(outRect.Width / pEnvelope.Width);

          pActiveView.Output(g.GetHdc().ToInt32(), dpi, ref rect, pEnvelope, null);

          g.ReleaseHdc();            

          return image;
     }

     catch (Exception excp)
     {
        MessageBox.Show(excp.Message + "將當前地圖轉出出錯,原因未知", "出錯提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

          return null;
      }
 }

  


?? 通過IExport接口實現的導出,也需要通過IActiveView的OutPut來實現,但其轉出句柄為IExport的StartExporting函數返回的DC,具體示例代碼如下:

Java代碼 復制代碼
  1. //輸出當前地圖至指定的文件???? ??
  2. public ? void ?ExportMapExtent(IActiveView?pView,?Size?outRect,string?outPath) ??
  3. {??????????? ??
  4. ???? try ??
  5. ????{ ??
  6. ???????? //參數檢查 ??
  7. ???????? if ?pView?==? null ?) ??
  8. ????????{ ??
  9. ???????????? throw ? new ?Exception( "輸入參數錯誤,無法生成圖片文件!" ); ??
  10. ????????}?? ??
  11. ???????? //根據給定的文件擴展名,來決定生成不同類型的對象 ??
  12. ????????ESRI.ArcGIS.Output.IExport?export?=? null ; ??
  13. ???????? if ?(outPath.EndsWith( ".jpg" )) ??
  14. ????????{ ??
  15. ????????????export?=? new ?ESRI.ArcGIS.Output.ExportJPEGClass(); ??
  16. ????????} ??
  17. ???????? else ? if ?(outPath.EndsWith( ".tiff" )) ??
  18. ????????{ ??
  19. ????????????export?=? new ?ESRI.ArcGIS.Output.ExportTIFFClass(); ??
  20. ????????} ??
  21. ???????? else ? if ?(outPath.EndsWith( ".bmp" )) ??
  22. ????????{ ??
  23. ????????????export?=? new ?ESRI.ArcGIS.Output.ExportBMPClass(); ??
  24. ????????} ??
  25. ???????? else ? if ?(outPath.EndsWith( ".emf" )) ??
  26. ????????{ ??
  27. ????????????export?=? new ?ESRI.ArcGIS.Output.ExportEMFClass(); ??
  28. ????????} ??
  29. ???????? else ? if ?(outPath.EndsWith( ".png" )) ??
  30. ????????{ ??
  31. ????????????export?=? new ?ESRI.ArcGIS.Output.ExportPNGClass(); ??
  32. ????????} ??
  33. ???????? else ? if ?(outPath.EndsWith( ".gif" )) ??
  34. ????????{ ??
  35. ????????????export?=? new ?ESRI.ArcGIS.Output.ExportGIFClass(); ??
  36. ????????} ??
  37. ??
  38. ????????export.ExportFileName?=?outPath; ??
  39. ????????IEnvelope?pEnvelope?=?pView.Extent; ??
  40. ???????? //導出參數??????????? ??
  41. ????????export.Resolution?=? 300 ; ??
  42. ????????tagRECT?exportRect?=? new ?tagRECT(); ??
  43. ????????exportRect.left?=?exportRect.top?=? 0 ; ??
  44. ????????exportRect.right?=?outRect.Width; ??
  45. ????????exportRect.bottom?=?( int )(exportRect.right?*?pEnvelope.Height?/?pEnvelope.Width); ??
  46. ????????ESRI.ArcGIS.Geometry.IEnvelope?envelope?=? new ?ESRI.ArcGIS.Geometry.EnvelopeClass(); ??
  47. ???????? //輸出范圍 ??
  48. ????????envelope.PutCoords(exportRect.left,?exportRect.top,?exportRect.right,?exportRect.bottom); ??
  49. ????????export.PixelBounds?=?envelope; ??
  50. ???????? //可用于取消操作 ??
  51. ????????ITrackCancel?pCancel?=? new ?CancelTrackerClass(); ??
  52. ????????export.TrackCancel?=?pCancel; ??
  53. ????????pCancel.Reset(); ??
  54. ???????? //點擊ESC鍵時,中止轉出 ??
  55. ????????pCancel.CancelOnKeyPress?=? true ; ??
  56. ????????pCancel.CancelOnClick?=? false ; ??
  57. ????????pCancel.ProcessMessages?=? true ; ??
  58. ???????? //獲取handle ??
  59. ????????System.Int32?hDC?=?export.StartExporting(); ??
  60. ???????? //開始轉出 ??
  61. ????????pView.Output(hDC,?(System.Int16)export.Resolution,?ref?exportRect,?pEnvelope,?pCancel); ??
  62. ????????bool?bContinue?=?pCancel.Continue(); ??
  63. ???????? //捕獲是否繼續 ??
  64. ???????? if ?(bContinue) ??
  65. ????????{?????????????????????????????? ??
  66. ????????????export.FinishExporting(); ??
  67. ????????????export.Cleanup(); ??
  68. ????????} ??
  69. ???????? else ??
  70. ????????{?????????????????? ??
  71. ????????????export.Cleanup(); ??
  72. ????????} ??
  73. ????????bContinue?=?pCancel.Continue();??????????????? ??
  74. ????} ??
  75. ???? catch ?(Exception?excep) ??
  76. ????{ ??
  77. ???????? //錯誤信息提示 ??
  78. ????} ??
  79. }?

ArcGIS Engine開發系列:將地圖導出為圖片的兩種方法


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 延川县| 广河县| 石河子市| 赞皇县| 甘谷县| 朔州市| 六盘水市| 内丘县| 资溪县| 桑日县| 保定市| 阿克陶县| 中超| 溧水县| 宁安市| 金溪县| 玛纳斯县| 上饶市| 陈巴尔虎旗| 抚宁县| 宁德市| 巴林左旗| 秦皇岛市| 安塞县| 洛南县| 漳浦县| 万宁市| 庆阳市| 正定县| 卫辉市| 五大连池市| 永安市| 江永县| 五峰| 乌拉特前旗| 山丹县| 华坪县| 腾冲县| 金秀| 年辖:市辖区| 枣阳市|