2012年6月28日 星期四

Google Street View Application (kinect) -- 2

Ref:
a. kinect SDK for windows v1.5 Green Screen -WPF
b. Google street view api

1. Green Screen WPF application
2. Add .NET Reference
    System.Drawing
    System.Windows.Forms
3. Add 3 methods (2 event methods) as follows
3-1 SaveWebPage2Image was used to convert google street view as a bitmap
3-2 Mouse_Up was used to replace the background image as a pre-defined street view
3-3 Mouse_Wheel was used to change the heading angle of the previous street view



  public System.Drawing.Bitmap SaveWebPage2Image(string url)
        {
            // Load the webpage into a WebBrowser control
            System.Windows.Forms.WebBrowser wb = new System.Windows.Forms.WebBrowser();
            wb.ScrollBarsEnabled = false;
            wb.ScriptErrorsSuppressed = true;
            wb.Navigate(url);

            while (wb.ReadyState != System.Windows.Forms.WebBrowserReadyState.Complete) { System.Windows.Forms.Application.DoEvents(); }

            // Take Screenshot of the web pages full width
            wb.Width = wb.Document.Body.ScrollRectangle.Width;

            // Take Screenshot of the web pages full height
            wb.Height = wb.Document.Body.ScrollRectangle.Height;

            // Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
            System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(wb.Width, wb.Height);
            wb.DrawToBitmap(bitmap, new System.Drawing.Rectangle(0, 0, wb.Width, wb.Height));
            wb.Dispose();

            return bitmap;
        }

        int angle1 = 120;
        private void Window_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {

           
            this.Title = "Headingangle : " + angle1.ToString();
            System.Drawing.Bitmap bmp = SaveWebPage2Image(@"http://maps.googleapis.com/maps/api/streetview?size=600x300&location=25.080067,121.397699&heading=" + angle1.ToString() + @"&fov=90&pitch=-10&sensor=false");
            IntPtr hBitmap = bmp.GetHbitmap();
            System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

            Backdrop.Source = WpfBitmap;
        }

        private void Window_MouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
        {
            angle1 += 20;
            this.Title = "Headingangle : " + angle1.ToString();
            System.Drawing.Bitmap bmp = SaveWebPage2Image(@"http://maps.googleapis.com/maps/api/streetview?size=600x300&location=25.080067,121.397699&heading=" + angle1.ToString() + @"&fov=90&pitch=-10&sensor=false");
            IntPtr hBitmap = bmp.GetHbitmap();
            System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

            Backdrop.Source = WpfBitmap;
        }
4. 下載

沒有留言:

張貼留言