C# 调用 Google Earth Com API开发(三)
2009-05-22 08:29:45 来源:WEB开发网这两处代码还比较简陋,比如未添加主窗口焦点检测,相信读者可以自行添加。O(∩_∩)O~
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: }
OK,这篇GE开发到此为止,请读者继续等待后面的精彩文章…
不好意思,刚才忘记上传源程序了!
http://files.cnblogs.com/wpwen/GEDemo_2009-05-22.rar
图片看不清楚?请点击这里查看原图(大图)。
图片看不清楚?请点击这里查看原图(大图)。
系列文章:
C#调用 GoogleEarth COM API开发(一)
C# 调用 Google Earth Com API开发(二)
- ››Google运作经理Bryan Power给出的GOOGLE求职意见
- ››Google用户体验的十大设计原则
- ››Google Analytics(分析)能为网站带来什么
- ››Google goggles图片搜索 如何优化一个wap网站
- ››Google Docs将增加iPhone和Android编辑功能
- ››Google Android操作系统内核编译图文教程
- ››google map api 与jquery结合使用--控件,监听器...
- ››google map api 与jquery结合使用(2) --标注,浮...
- ››google map api 与jquery结合使用(3) --图标样式...
- ››Google 首页代码分析及简评
- ››Google财经更新iPhone和Android版本
- ››Google否认Android应用认证体系被破解
赞助商链接