首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

C# 呼叫 Google Earth COM API 開發(三):截圖功能實作(黑白與彩色)

     編輯:關於C語言

實作兩種截圖方式:

1. Google Earth 內建截圖(僅黑白)

GEViewContent view = GetGEView();
if (view != null) {
    ApplicationGE ge = view.GeApplication;
    if (ge != null && ge.IsInitialized() > 0) {
        using (SaveFileDialog sfd = new SaveFileDialog()) {
            sfd.Filter = "JPG|*.jpg";
            if (sfd.ShowDialog() == DialogResult.OK)
                ge.SaveScreenShot(sfd.FileName, 100);
        }
    }
}

2. 彩色截圖(Vista/Win7 不支援,XP/Server2003 可用)

IntPtr hRender = view.GeRenderHWnd;
if (hRender != IntPtr.Zero) {
    IntPtr hRenderDC = NativeMethods.GetWindowDC(hRender);
    IntPtr hBitmap = NativeMethods.CreateCompatibleBitmap(hRenderDC, width, height);
    IntPtr hMemDC = NativeMethods.CreateCompatibleDC(hRenderDC);
    NativeMethods.SelectObject(hMemDC, hBitmap);
    NativeMethods.BitBlt(hMemDC, 0, 0, width, height, hRenderDC, 0, 0, 0x00CC0020); // SRCCOPY
    using (Bitmap bmp = Bitmap.FromHbitmap(hBitmap)) {
        bmp.Save(sfd.FileName, ImageFormat.Jpeg);
    }
    NativeMethods.DeleteDC(hRenderDC);
    NativeMethods.DeleteDC(hMemDC);
}

彩色截圖透過 GDI 複製渲染裝置內容,繞過 GE 內建限制,但受作業系統桌面合成影響,較新 OS 需改用 DWM API 或其他方案。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved