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. 下載

2012年6月27日 星期三

Google Street View WPF Application -- 1

將Google 街景圖以WPF之Image控制項展示。
1. 加入WIndowForm元件。 

// Add ref System.Drawing
//         System.Windows.Forms
2. 加入html2bitmap方法

        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;
        }
3. 初始設定
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //convert System.Drawing.Image to WPF image
            System.Drawing.Bitmap bmp = SaveWebPage2Image(@"http://maps.googleapis.com/maps/api/streetview?size=600x300&location=25.080067,121.397699&heading=300&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());
            im.Source = WpfBitmap;
        }
4. MouseUp Event 改辦視角
        int angle1 = 120;
        private void Window_MouseUp(object sender, MouseButtonEventArgs 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());
            im.Source = WpfBitmap;
        }
    }
}
5. 下載

Convert url to bitmap and then WPF(Image)

Ref: Wait to add

1. There are some examples to save webpage into bitmap.

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;
        }
2. xaml file
 <Grid>
        <Image Name="im" />
    </Grid>
3. Add System.Drawing and System.Windows.Forms
4. Window_Loaded
   private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            
            //convert System.Drawing.Image to WPF image
            System.Drawing.Bitmap bmp = SaveWebPage2Image(@"http://www.google.com.tw");
            IntPtr hBitmap = bmp.GetHbitmap();
            System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

            im.Source = WpfBitmap;
        }
5. 

2012年6月26日 星期二

Speech SDK 11 -- 2

中文語音辨識 (ASUS A43S with Windows 7 x64)
1) Re-Install Speech SDK
1-1 Repair speeh platform runtime
      http://www.microsoft.com/en-us/download/details.aspx?id=27225
1-2 Repair Speech SDK
      http://www.microsoft.com/en-us/download/details.aspx?id=27226
1-3 Install speech runtime Language (zh-TW)
     http://www.microsoft.com/en-us/download/details.aspx?id=27224#instructions
2) Add Ref :C:\Program Files\Microsoft SDKs\Speech\v11.0\Assembly\Microsoft.Speech.dll

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Speech.Recognition;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a new SpeechRecognitionEngine instance.
            SpeechRecognitionEngine sre = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("zh-TW"));

            // Create a simple grammar that recognizes "red", "green", or "blue".
            Choices colors = new Choices();
            colors.Add("向上");
            colors.Add("向下");
            colors.Add("左");
            colors.Add("右");
            colors.Add("前");
            colors.Add("後");

            GrammarBuilder gb = new GrammarBuilder();
            gb.Append(colors);

            // Create the actual Grammar instance, and then load it into the speech recognizer.
            Grammar g = new Grammar(gb);
            sre.LoadGrammar(g);

            // Register a handler for the SpeechRecognized event.
            sre.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(sre_SpeechRecognized);
            sre.SetInputToDefaultAudioDevice();
            sre.RecognizeAsync(RecognizeMode.Multiple);
            while (true)
            { }

        }

        static void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            Console.WriteLine(e.Result.Text);
        }
    }
}

2012年4月30日 星期一

HWIT-NetworkCredential basicCredential


1. 在HWIT以SmtpClient發送內部郵件OK,外送郵件需驗證      
        public static void SendMail(string 人, string 信)
        {
            //------- 認證
            SmtpClient smtpClient = new SmtpClient();
            MailAddress from = new MailAddress("csjou@mail.hwc.edu.tw");
            smtpClient.Host = "mail.hwc.edu.tw";
            //NetworkCredential basicCredential =
            //    new NetworkCredential("csjou", "xxxxxxxx");
            //smtpClient.UseDefaultCredentials = false;
            //smtpClient.Credentials = basicCredential;
            // Set destinations for the e-mail message.
            MailAddress to = new MailAddress(人);
            // Specify the message content.
            MailMessage message = new MailMessage(from, to);
            message.Body = 信;
            // Include some non-ASCII characters in body and subject.
            string someArrows = new string(new char[] { '\u2190', '\u2191', '\u2192', '\u2193' });
            message.Body += Environment.NewLine + someArrows;
            message.BodyEncoding = System.Text.Encoding.UTF8;
            message.Subject = "test message 1" + someArrows;
            message.SubjectEncoding = System.Text.Encoding.UTF8;
            //string 附檔 = @"C:\Users\Public\Pictures\Sample Pictures\Desert.jpg";
            //Attachment 附件 = new Attachment(附檔);
            //message.Attachments.Add(附件);
            smtpClient.Send(message);
            Console.WriteLine("Sending message... press c to cancel mail. Press any other key to exit.");
            string answer = Console.ReadLine();
            // If the user canceled the send, and mail hasn't been sent yet,
            // then cancel the pending operation.
            if (answer.StartsWith("c") && mailSent == false)
            {
                smtpClient.SendAsyncCancel();
            }
            // Clean up.
            message.Dispose();
            Console.WriteLine("Goodbye.");
        }
2.
3. 解除紅字註解(加入個人帳號、密碼驗證),可以寄出外送郵件

2012年4月18日 星期三

SCVMM 自助使用者建置程序

自助使用者為網域使用者,在VMM中建置自助使用者角色,將此角色權限授於網域群組,將VM等權限設完後。
1. AD 建自助使用者群組


2. VMM 建立VMM新角色
2-1 加入自助使用者角色



2-2 依序依據加入角色設定權限,設定使用實體機範圍、建立、使用虛擬機權限等。
3. 建立AD使用者,納為自助使用者群組