亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

ArcGIS Engine開發(fā)系列:將地圖導(dǎo)出為圖片的兩

系統(tǒng) 2040 0

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

Java代碼 復(fù)制代碼
  1. ///?<summary> ??
  2. ??
  3. ///?將Map上指定范圍(該范圍為規(guī)則區(qū)域)內(nèi)的內(nèi)容輸出到Image,注意,當(dāng)圖片的行數(shù)或列數(shù)超過10000左右時(shí),出現(xiàn)原因示知的失敗 ??
  4. ??
  5. ///?</summary> ??
  6. ??
  7. ///?<param?name="pMap">需轉(zhuǎn)出的MAP</param> ??
  8. ///?<param?name="outRect">輸出的圖片大小</param> ??
  9. ///?<param?name="pEnvelope">指定的輸出范圍(為Envelope類型)</param> ??
  10. ///?<returns>輸出的Image?具體需要保存為什么格式,可通過Image對(duì)象來實(shí)現(xiàn)</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. ?????????? //轉(zhuǎn)換成activeView,若為ILayout,則將Layout轉(zhuǎn)換為IActiveView ??
  21. ??????????IActiveView?pActiveView?=?(IActiveView)pMap; ??
  22. ?????????? //?創(chuàng)建圖像,為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?+? "將當(dāng)前地圖轉(zhuǎn)出出錯(cuò),原因未知" ,? "出錯(cuò)提示" ,?MessageBoxButtons.OK,?MessageBoxIcon.Error); ??
  41. ??
  42. ?????????? return ? null ; ??
  43. ??????} ??
  44. ?}??
    /// <summary>

/// 將Map上指定范圍(該范圍為規(guī)則區(qū)域)內(nèi)的內(nèi)容輸出到Image,注意,當(dāng)圖片的行數(shù)或列數(shù)超過10000左右時(shí),出現(xiàn)原因示知的失敗

/// </summary>

/// <param name="pMap">需轉(zhuǎn)出的MAP</param>
/// <param name="outRect">輸出的圖片大小</param>
/// <param name="pEnvelope">指定的輸出范圍(為Envelope類型)</param>
/// <returns>輸出的Image 具體需要保存為什么格式,可通過Image對(duì)象來實(shí)現(xiàn)</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
      {                
          //轉(zhuǎn)換成activeView,若為ILayout,則將Layout轉(zhuǎn)換為IActiveView
          IActiveView pActiveView = (IActiveView)pMap;
          // 創(chuàng)建圖像,為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 + "將當(dāng)前地圖轉(zhuǎn)出出錯(cuò),原因未知", "出錯(cuò)提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

          return null;
      }
 }

  


?? 通過IExport接口實(shí)現(xiàn)的導(dǎo)出,也需要通過IActiveView的OutPut來實(shí)現(xiàn),但其轉(zhuǎn)出句柄為IExport的StartExporting函數(shù)返回的DC,具體示例代碼如下:

Java代碼 復(fù)制代碼
  1. //輸出當(dāng)前地圖至指定的文件???? ??
  2. public ? void ?ExportMapExtent(IActiveView?pView,?Size?outRect,string?outPath) ??
  3. {??????????? ??
  4. ???? try ??
  5. ????{ ??
  6. ???????? //參數(shù)檢查 ??
  7. ???????? if ?pView?==? null ?) ??
  8. ????????{ ??
  9. ???????????? throw ? new ?Exception( "輸入?yún)?shù)錯(cuò)誤,無法生成圖片文件!" ); ??
  10. ????????}?? ??
  11. ???????? //根據(jù)給定的文件擴(kuò)展名,來決定生成不同類型的對(duì)象 ??
  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. ???????? //導(dǎo)出參數(shù)??????????? ??
  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. ???????? //點(diǎn)擊ESC鍵時(shí),中止轉(zhuǎn)出 ??
  55. ????????pCancel.CancelOnKeyPress?=? true ; ??
  56. ????????pCancel.CancelOnClick?=? false ; ??
  57. ????????pCancel.ProcessMessages?=? true ; ??
  58. ???????? //獲取handle ??
  59. ????????System.Int32?hDC?=?export.StartExporting(); ??
  60. ???????? //開始轉(zhuǎn)出 ??
  61. ????????pView.Output(hDC,?(System.Int16)export.Resolution,?ref?exportRect,?pEnvelope,?pCancel); ??
  62. ????????bool?bContinue?=?pCancel.Continue(); ??
  63. ???????? //捕獲是否繼續(xù) ??
  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. ???????? //錯(cuò)誤信息提示 ??
  78. ????} ??
  79. }?

ArcGIS Engine開發(fā)系列:將地圖導(dǎo)出為圖片的兩種方法


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

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

【本文對(duì)您有幫助就好】

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

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 亚洲国产精品专区 | 4hu永久影院在线四虎 | 精品久久久99大香线蕉 | 天天干天天操天天 | 日韩中文字幕精品免费一区 | 91中文字幕在线观看 | 亚洲精品9999久久久久 | 亚洲精品黄色 | 国产福利在线 | 日本不卡毛片一二三四 | 九九99九九精彩 | 欧美在线香蕉在线现视频 | 日本岛国片在线观看 | 亚洲一区二区三区高清不卡 | 色偷偷久久一区二区三区 | 日本一区二区三区四区公司 | 国产成人精品日本亚洲语言 | 99国产精品 | 亚洲一区成人 | 国产日韩欧美亚洲精品95 | 久久免费视频2 | 亚洲艹逼 | 国产一区二区三区不卡在线观看 | 精品一区二区三区免费视频 | 欧美成人精品高清在线播放 | 日韩精品在线一区 | 欧美国产综合在线 | 中文字幕一区二区三区四区 | 天堂成人精品视频在线观 | 夜夜爽夜夜操 | 久久青青草原精品影院 | 第一色网站 | 日本欧美久久久久免费播放网 | 奇米激情| 一级女人18毛片免费 | 中文字幕一区在线观看 | 99这里只有精品6 | 曰本毛片va看到爽不卡 | 色www精品视频在线观看 | 好好的日com欧美 | 香港a毛片免费全部播放 |