程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> C#調用Google Earth Com API開發(三)(4)

C#調用Google Earth Com API開發(三)(4)

編輯:關於C語言

3、截圖

程序中有兩種截圖功能,一種是GoogleEarth自帶的截圖功能,只能截取黑白圖片;另一種為彩色截圖 ,但是Vista以上操作系統不支持,還未找到合適的方法實現Vista與Win7兼容。

1) GoogleEarth自帶截圖功能:

1: GEViewContent view = GetGEVIEw();
2:
3: if (vIEw != null)
4: {
5:   ApplicationGE ge = vIEw.GeApplication;
6:   if (ge != null && ge.IsInitialized() > 0)
7:   {
8:     using (SaveFileDialog sfd = new SaveFileDialog())
9:     {
10:       sfd.Filter = "jpg圖片|*.jpg";
11:       sfd.AddExtension = true;
12:       sfd.CheckPathExists = true;
13:       sfd.Title = "保存Google Earth截圖";
14:
15:       if (sfd.ShowDialog() == DialogResult.OK)
16:       {
17:         ge.SaveScreenShot(sfd.FileName, 100);
18:       }
19:     }
20:   }
21: }

2) 彩色截圖:

1: GEViewContent view = GetGEVIEw();
2: if (vIEw != null)
3: {
4:   int nWidth = vIEw.Control.Width;
5:   int nHeight = vIEw.Control.Height;
6:   Point pt = view.Control.PointToScreen(vIEw.Control.Location);
7:   int nXSrc = pt.X;
8:   int nYSrc = pt.Y;
9:
10:   IntPtr hRender = vIEw.GeRenderHWnd;
11:
12:   if (hRender != IntPtr.Zero)
13:   {
14:     // 取得Render DC
15:     IntPtr hRenderDC = NativeMethods.GetWindowDC(hRender);
16:     // 創建hBitmap
17:     IntPtr hBitmap = NativeMethods.CreateCompatibleBitmap(hRenderDC,  nWidth, nHeight);
18:     // 創建MEM DC
19:     IntPtr hMemDC = NativeMethods.CreateCompatibleDC(hRenderDC);
20:     // 將Bitmap Select到MemDC
21:     NativeMethods.SelectObject(hMemDC, hBitmap);
22:     // 直接拷屏
23:     NativeMethods.BitBlt(hMemDC, 0, 0, nWidth, nHeight,
24:       hRenderDC, 0, 0, 13369376);
25:
26:     using(Bitmap bmp = Bitmap.FromHbitmap(hBitmap))
27:     {
28:       using(SaveFileDialog sfd = new SaveFileDialog())
29:       {
30:         sfd.Filter = "JPG圖片|*.jpg|PNG圖片|*.png";
31:         sfd.AddExtension = true;
32:         sfd.CheckPathExists = true;
33:         sfd.Title = "保存Google Earth截圖";
34:
35:         if (sfd.ShowDialog() == DialogResult.OK)
36:         {
37:           ImageFormat imgFormat = null;
38:           // 默認選擇JPG
39:           if (sfd.FilterIndex == 0)
40:           {
41:             imgFormat = ImageFormat.Jpeg;
42:           }
43:           // 選擇PNG
44:           else
45:           {
46:             imgFormat = ImageFormat.Png;
47:           }
48:           bmp.Save(sfd.FileName, imgFormat);
49:         }
50:       }
51:
52:       //銷毀資源
53:       NativeMethods.DeleteDC(hRenderDC);
54:       NativeMethods.DeleteDC(hMemDC);
55:     }
56:   }

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved