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: }