2012年12月27日 星期四

Word 無法刪除格線

Word 2010 x64 版(OS: Windows 7)
1. 三個 '-' 可以產生分隔線。
2. 運氣不好'文字格線被設定時,貼齊格線'被啟用。
3. 無法刪除格線。
4. 解決之道
    上下各加一空白段落,將格線夾在中間
    進格式解除
5. 刪除此上下空白選項即可。


2012年12月19日 星期三

Process Stereo Video Files 1 -- Merge Files

1. Objective : Merge 2 files.
2. Hardware:
    2-1 HTC EVO : Acquire stereo files in mp4 format.
    2-2 ASUS a43sv (Windows 7 x 64)
    2-3 Software:
          2-3-1. Freemake video converter 3.2.1.0 : Convert mp4 to wmv.
          2-3-2. Expression 4.0 pro (w/o codec): can't process mp4 file.
          2-3-3. Visual studio 2010 (x86)
          2-3-4. CyberLink PowerDVD10 : Play stereo video
 3 C# procedure
    3-1. Load 2 stereo files in wmv format (Converted by Freemake Video Converter)
    3-2. Merge 2 files by the method from expression sample program.
    3-3. Call a process to start cyberlink powerdvd and play the merge file.
    3-4. A button allows user to kill the process of the player.

   

2012年12月9日 星期日

Kinect SDK+ Speech SDK + Google Street View

OS: Windows 7 x64
Tools: Visual Studio 2010, Kinect SDK1.5, Speech SDK 11
Hardware: ASUS A43S, XBOX 360 Kinect.
1. Kinect SDK GreenScreen-WPF
2. WindowLoaded
     Add
     2-1 remove AllFrameReady event
     this.sensor.AllFramesReady -= this.SensorAllFramesReady;
     2-2 Add timier 10 secs
            計時器.Interval = new TimeSpan(0, 0, 10); // 10 secs
            計時器.Tick += new EventHandler(計時器_Tick);
            計時器.Start();
     2-3 Add voice commands
            Choices CMDs = new Choices();
            for (int i = 0; i < 地點名稱陣列.Length; i++)
                CMDs.Add(地點名稱陣列[i]);
            ....
      2-4 Timer event: Enable sensor and disable voice command or vice verse
            if (EventOn)
            {
                EventOn = false;
                this.sensor.AllFramesReady -= this.SensorAllFramesReady;
                sre.RecognizeAsync(RecognizeMode.Multiple);
            }
            else
            {
                EventOn = true;
                this.sensor.AllFramesReady += this.SensorAllFramesReady;
                sre.RecognizeAsyncCancel();
            }
3.
4. 下載

2012年12月8日 星期六

Disable event trigger for a fixed period

OS : Windows 7 x64
Tool: Visual Studio 2010 ultimate SP1
WPF application
1. To make 2  window events as Load and MouseWheel, the former is used to set the fixed period timer while the latter is used to generate the simulate event.
2. The trigger of MouseWheel will sent now to the title of window.


private void Window_MouseWheel(object sender, MouseWheelEventArgs e)
        {
            this.Title += " " + DateTime.Now.Millisecond.ToString();
            EventOn = false;
            this.MouseWheel -= new MouseWheelEventHandler(Window_MouseWheel);
            t1.Stop();
            t1.Start();
        }
        System.Windows.Threading.DispatcherTimer t1 = new System.Windows.Threading.DispatcherTimer();
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

            t1.Interval = new TimeSpan(0, 0, 0, 0, 200); //200 miliseconds
            t1.Tick += new EventHandler(t1_Tick);
            t1.Start();
        }

        bool EventOn = true;
        void t1_Tick(object sender, EventArgs e)
        {
            //this.Title += DateTime.Now.ToString();
            if (EventOn)
            {
                EventOn = false;
                this.MouseWheel -= new MouseWheelEventHandler(Window_MouseWheel);
            }
            else
            {
                EventOn = true;
                this.MouseWheel += new MouseWheelEventHandler(Window_MouseWheel);
            }
        }
3. Example shows the period may not being exactly 200 ms.


2012年12月3日 星期一

Speech SDK 語音辨識範例

1. OS: Windows 7 x64
2. Tools: VS 2010
               Speech SDK x64 (Install Runtime, SDK and then TTS SR zh-TW)
3.

<Grid>
        <Ellipse Name="OO" Margin="0,0,0,0" Stroke="Red" StrokeThickness="20" Visibility="Hidden"/>
        <Grid Name="XX" Margin="0,0,0,0" Visibility="Hidden" >
            <Line Stroke="Blue" StrokeThickness="20" X1="0" Y1="0" X2="525" Y2="350"/>
            <Line Stroke="Blue" StrokeThickness="20" X1="0" Y1="350" X2="525" Y2="0"/>
        </Grid>
  </Grid>
4.

// 1. Add Ref Microsoft Speech Object Library v 11 Not in COM
// C:\Program Files\Microsoft SDKs\Speech\v11.0\Assembly\Microsoft.Speech.dll
using Microsoft.Speech.Recognition;

namespace WPFOX1
{
    /// <summary>
    /// MainWindow.xaml 的互動邏輯
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // Create a new SpeechRecognitionEngine instance.
            SpeechRecognitionEngine sre = new SpeechRecognitionEngine(new System.Globalization.CultureInfo("zh-TW"));
            // SpeechRecognitionEngine sre = new SpeechRecognitionEngine();

            // 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.SpeechRecognitionRejected += new EventHandler<SpeechRecognitionRejectedEventArgs>(sre_SpeechRecognitionRejected);
            sre.SetInputToDefaultAudioDevice();
            sre.RecognizeAsync(RecognizeMode.Multiple);
        }

        void sre_SpeechRecognitionRejected(object sender, SpeechRecognitionRejectedEventArgs e)
        {
            this.Title = e.ToString();
        }

        void sre_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            //this.Title = e.ToString();
            switch (e.Result.Text)
            {
                case "對":
                case "是":
                case "圈":
                    OO.Visibility = System.Windows.Visibility.Visible;
                    XX.Visibility = System.Windows.Visibility.Hidden;
                    break;
                case "錯":
                case "差":
                case "不對":
                    OO.Visibility = System.Windows.Visibility.Hidden;
                    XX.Visibility = System.Windows.Visibility.Visible;
                    break;
                default:
                    OO.Visibility = System.Windows.Visibility.Hidden;
                    XX.Visibility = System.Windows.Visibility.Hidden;
                    break;
            }
        }
    }
5 結果




2012年11月23日 星期五

Expression Encoder SDK Ex1

1. OS and Tools : Windows 8 + Expression 4 + VS2012
2. Sample code @
    C:\Program Files (x86)\Microsoft Expression\Encoder 4\SDK\Samples\Live
3. This program send a video (file) streaming into localhost:8080
4. Copy Wildlife.wmv into the same directory as live.exe
5. live Wildlie.wmv nd open the IE with url as mms://localhost:8080/

2012年10月26日 星期五

FileTracker:error FTK1011

Ref: http://www.dotblogs.com.tw/ricochen/archive/2010/06/15/15889.aspx

1. Download 3DTools souce code.
2. System: Mac Pro: VM : Windows 7 x64
    Tools: VS 2010
3. Open demo project with FileTracker error.
4. Solve problem by changing compiler from .net framework 3.0 to 4.0 as described in ref.

2012年10月23日 星期二

xbox controller test 2 (C#)

0-1 Hardware : ASUS A43S
0-2 OS: Windows 7 (x64)
0-3 Tools: VS 2010 (x86)
       - 1. XBox Controller Driver
              http://www.microsoft.com/hardware/en-us/d/xbox-360-wireless-controller-for-windows
       - 2. SlimDX x86 Runtime
              http://slimdx.org/download.php
1. using SlimDX.DLL (Downloadable)
2. Employ controls.cs from the example of the previous program.
3. using Xbox360Controller;
4. In the class of forms,

       GamepadState controls;
        Timer t1 = new Timer();
        private void Form1_Load(object sender, EventArgs e)
        {
            controls = new GamepadState(0);
            t1.Interval = 100;
            t1.Tick += new EventHandler(t1_Tick);
            t1.Start();
        }

        int i = 0;
        void t1_Tick(object sender, EventArgs e)
        {
            controls.Update();
            //this.Text = controls.LeftStick.Position.X.ToString() + ","
            //    + controls.LeftStick.Position.Y.ToString();
            //this.Text += (i++).ToString();
            if (controls.LeftStick.Position.X > 0.5) button1.Location = new Point(button1.Location.X + 10, button1.Location.Y);
            if (controls.LeftStick.Position.X < -0.5) button1.Location = new Point(button1.Location.X - 10, button1.Location.Y);
            if (controls.LeftStick.Position.Y > 0.5) button1.Location = new Point(button1.Location.X, button1.Location.Y-10);
            if (controls.LeftStick.Position.Y < -0.5) button1.Location = new Point(button1.Location.X, button1.Location.Y+10);
        }
5. All of the switches in the xbox controller can be read by a timer base event method();
6. Examples

XBOX360Controller Test

ref : http://visualcsharp.webs.com/projectdownloads.htm

1. Hardware: ASUS A43S, Microsoft wireless xbox controller
2. OS: Windows 8 (x64)
3. Tools: VS 2010(x86)

Download SlimDX (.NET4.0, x86) ** Notes x64 won't work.
http://slimdx.org/download.php


2012年9月30日 星期日

三球儀自轉公轉設定


三球儀公自轉設定(以WPF  3D Sphere 物件為例)
1.  腳本設定

<Grid.Triggers>
            <EventTrigger RoutedEvent="UserControl.Loaded" >
                <BeginStoryboard>
                    <Storyboard Name="myStoryBoard">
                        <DoubleAnimation
            Storyboard.TargetName="自轉"
            Storyboard.TargetProperty="Angle"
            From="0" To="360" Duration="0:0:1" RepeatBehavior="Forever"/>
                        <DoubleAnimation
            Storyboard.TargetName="公轉"
            Storyboard.TargetProperty="Angle"
            From="0" To="360" Duration="0:0:10" RepeatBehavior="Forever"/>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Grid.Triggers>
2.  自、公轉軸設定

<ModelVisual3D.Transform>
   <Transform3DGroup>
<!-- 先設定自轉軸  --!>
      <RotateTransform3D CenterX="0" CenterY="0" CenterZ="0">
                                    <RotateTransform3D.Rotation>
                                        <AxisAngleRotation3D  x:Name="自轉" Angle="0" Axis="0.3,1,0" />
                                    </RotateTransform3D.Rotation>
       </RotateTransform3D>
<!-- 平移公轉半徑 --!>
       <TranslateTransform3D OffsetX="3" OffsetY="0" OffsetZ="0"  />
<!-- 設定公轉軸--!>
       <RotateTransform3D>
                  <RotateTransform3D.Rotation>
                              <AxisAngleRotation3D  x:Name="公轉" Angle="0"   Axis="0,1,0" />
                   </RotateTransform3D.Rotation>
       </RotateTransform3D>
                            </Transform3DGroup>
 </ModelVisual3D.Transform>

2012年8月24日 星期五

VMM 2008 R2 PowerShell --- 1 (Domain Admin 權限)

1. 以網域管理者登入VMM主機,開啟PowerShell問題


載入延伸類型資料檔案時發生下列錯誤:
Microsoft.SystemCenter.VirtualMachineManager,C:\Program Files\Microsoft System
Center Virtual Machine Manager 2008 R2\bin\virtualmachinemanager.types.ps1xml :
檔案已因下列驗證例外狀況而被略過: C:\Program Files\Microsoft System Center Virtu
al Machine Manager 2008 R2\bin\virtualmachinemanager.types.ps1xml 檔案無法載入,
因為它的執行已遭軟體限制原則封鎖。如需詳細資訊,請連絡系統管理員。。

2. 問題
     Local administrator 登入,可以載入模組,但無法與VMM連線
     網域管理者可以連線,但無法載入模組
3. 重新建立網用使用者,加入網域管理者群組,工作正常。



2012年7月26日 星期四

Bootable USB

Ref:http://www.intowindows.com/bootable-usb/

1. Hardware: Transcend 8G USB
2. Target Windows 7 x64
3. CMD by role of administrator
4. diskpart/list disk/ Select Disk #/clean
5.create partition primary/select partition 1/active/format fs=ntfs
6. assign
7. exit
8. g: (Windows 7 @ Driver G:)
9. cd boot
10. Bootsect.exe /NT60 I:     (USB @ Driver I:)
11. cd\
12. xcopy *.* I: /s   (Change to root and copy all files into USB driver)




2012年7月3日 星期二

emgu WPF facedetection

To combine WPF,cameraCapture and faceDetection
1. WPF example (Key function)
public static BitmapSource ToBitmapSource(IImage image)
2. CameraCapture acquires images in windowform control, it may be converted into WPF image by the previous method.
3. Get the image and detect face and eyes, passing it into WPF image.
    Notes: Add System.Drawing for some of items such as Size ==> System.Drawing.Size,
               Color -> System.Drawing.Color ... etc.

    public Window1()
        {
            InitializeComponent();
            this.Dispatcher.Hooks.DispatcherInactive += new EventHandler(ProcessFrame);
            _capture = new Capture();
        }

        private Capture _capture;
        private bool _captureInProgress;
        private void ProcessFrame(object sender, EventArgs arg)
        {
            Image<Bgr, Byte> frame = _capture.QueryFrame();
            Image<Gray, Byte> gray = frame.Convert<Gray, Byte>(); //Convert it to Grayscale

            //Stopwatch watch = Stopwatch.StartNew();
            this.Dispatcher.Hooks.DispatcherInactive -= new EventHandler(ProcessFrame);
            //normalizes brightness and increases contrast of the image
            gray._EqualizeHist();

            //Read the HaarCascade objects

            HaarCascade face = new HaarCascade("haarcascade_frontalface_alt_tree.xml");
            HaarCascade eye = new HaarCascade("haarcascade_eye.xml");

            //Detect the faces  from the gray scale image and store the locations as rectangle
            //The first dimensional is the channel
            //The second dimension is the index of the rectangle in the specific channel
            MCvAvgComp[][] facesDetected = gray.DetectHaarCascade(
               face,
               1.1,
               10,
               Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
               new System.Drawing.Size(20, 20));

            foreach (MCvAvgComp f in facesDetected[0])
            {
                //draw the face detected in the 0th (gray) channel with blue color
                //image.Draw(f.rect, new Bgr(Color.Blue), 2);
                frame.Draw(f.rect, new Bgr(System.Drawing.Color.Blue), 2);

                //Set the region of interest on the faces
                gray.ROI = f.rect;
                MCvAvgComp[][] eyesDetected = gray.DetectHaarCascade(
                   eye,
                   1.1,
                   10,
                   Emgu.CV.CvEnum.HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,
                   new System.Drawing.Size(20, 20));
                gray.ROI = System.Drawing.Rectangle.Empty;

                foreach (MCvAvgComp e in eyesDetected[0])
                {
                    System.Drawing.Rectangle eyeRect = e.rect;
                    eyeRect.Offset(f.rect.X, f.rect.Y);
                    frame.Draw(eyeRect, new Bgr(System.Drawing.Color.Red), 2);
                }
            }

            image1.Source = ToBitmapSource(frame);
            this.Dispatcher.Hooks.DispatcherInactive += new EventHandler(ProcessFrame);
        }
4. 下載

2012年7月2日 星期一

Emgu x64 FaceDetection

Ref: http://lucas-0706.blogspot.tw/2012/02/emgu-cv-on-visual-c-2010.html
電腦 ASUS A43S, OS: Windows 7 x64

1. 加入參考路徑 C:\Users\csjou\Downloads\emgux64\libemgucv-windows-x64-2.2.1.1150\libemgucv-windows-x64-2.2.1.1150\bin\
2. 重新加入 Emgu.DLL, Emgu.CV.DLL, Emgu.Util
3. 重新加入既有項目
    CommonAssemblyInfo.cs
    haarcascade_eye.xml
    haarcascade_frontalface_alt_tree.xml
4. 變更檔案屬性為永遠複製
      haarcascade_eye.xml
      haarcascade_frontalface_alt_tree.xml
5. 變更輸出bin位置
6. 變更我的電腦 環境變數 Path 加入 C:\Users\csjou\Downloads\emgux64\libemgucv-windows-x64-2.2.1.1150\libemgucv-windows-x64-2.2.1.1150\bin\
7. 結果:




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使用者,納為自助使用者群組




SCVMM自助使用者網站無法登入

轉了一圈,原來是SQL Server 未啟動。
1.  自助使用者網站無法登入(Login 後沒反應)
2.  啟動 SCVMM 檢查,無法登入
3. 改用Administrator role 啟動
4. 學生說SQL未啟動
4-1 SQL Server 無法登入 (Shutdown 後未啟動)
4-2 啟動 SQL Server Agent 並改為自動登入(本系統設定為omadmin)
5. 看來正常



2012年4月8日 星期日

Error 1068: Remote Access Connection Manager service

1. 遠端桌面無法啟用
2. 啟用 Access Connection Manager,由內容選項,先啟用相依服務。
3. 啟用 Terminal Services, Terminal Services Configuration, Terminal Service UserMode Port Redirector.


2012年4月6日 星期五

PDFBox-2

1. Ref: http://naspinski.net/post/ParsingReading-a-PDF-file-with-C-and-AspNet-to-text.aspx
2. Add Ref
// PDFBox/bin:
//2-1 FontBox-0.1.0-dev.dll
//2-2 IKVM.GNU.Classpath.dll
//2-3 IKVM.Runtime.dll
//2-4 PDFBox-0.7.3.dll
// 3. using
using org.pdfbox.pdmodel;
using org.pdfbox.util;
// 4
using System.IO;
// 5 Add parsePDF method

public static void parsePDF(string pdf_in, string txt_out)
        {
            StreamWriter sw = new StreamWriter(txt_out, false);
            try
            {
                sw.WriteLine();
                sw.WriteLine(DateTime.Now.ToString());
                PDDocument doc = PDDocument.load(pdf_in);
                PDFTextStripper stripper = new PDFTextStripper();
                sw.Write(stripper.getText(doc));
            }
            catch (Exception ex) { Console.Write(ex.Message); }
            finally
            {
                sw.Close();
                sw.Dispose();
            }
        }
// 6. Console mode project

      static void Main(string[] args)
        {
            string pdf_in = @"E:\Working\PDF2Text\TryExe\101050_1401.PDF";
            string txt_out = "Test.txt";
            parsePDF(pdf_in, txt_out);
            Console.WriteLine("Done!");
        }


PDFBox-1

Ref: http://naspinski.net/post/ParsingReading-a-PDF-file-with-C-and-AspNet-to-text.aspx
1. Download http://sourceforge.net/projects/pdfbox/
2. Unzip PDFBox-0.7.3.zip
3. bin/ExtractText.exe
4. 未設定編碼




5. ExtractText -encoding UTF-8 xxx.PDF ooo.txt

Helix 3D Toolkit--2

1. WPF 專案
2. 確認已安裝NuGet Package

3.參考處加入 Helix Toolkit
4. xaml 檔 加入ns
<Window x:Class="AInstallEx1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:helix="clr-namespace:HelixToolkit.Wpf;assembly=HelixToolkit.Wpf" 
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid>
            <helix:HelixViewport3D x:Name="view1" Background="DarkGreen" IsHeadLightEnabled="True">
                <!--<helix:DefaultLightsVisual3D/>-->
            </helix:HelixViewport3D>
        </Grid>
    </Grid>
</Window>
5. C# 加入
using HelixToolkit.Wpf;
using System.Windows.Media.Media3D;

namespace AInstallEx1
{
    /// <summary>
    /// MainWindow.xaml 的互動邏輯
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            MeshBuilder mb = new MeshBuilder();
            mb.AddBox(new Point3D(0, 0, 0), 2, 2, 2);
            view1.Children.Add(
            new ModelVisual3D { Content = new GeometryModel3D { Geometry =  mb.ToMesh(), Material = Materials.White } }
            );
        }
    }
}
6. Done!






Helix 3D Toolkit -- 1

Ref: http://helixtoolkit.codeplex.com/
有許多WPF 3D範例,值得認真讀一讀。
需要 nunit.framework.dll 可由此下載
http://www.nunit.org/index.php?p=samples&r=2.6



2012年3月27日 星期二

Speech Platform v11 -- 1

文字轉語音又弄了半天半,擔心x64平台,x86發展工具
1. 系統說明
    Windows 7 x64 作業系統
    VS2010 x86 工具
    ASUS A43S 筆電
2. Ref : http://www.microsoft.com/download/en/details.aspx?id=27224

Instructions


  • First install the Microsoft Speech Platform - Runtime 11.0
  • Click the file you want to download from the list below.
  • Do one of the following:
    • To start the installation immediately, click Open or Run this program from its current location.
    • To copy the download to your computer for installation at a later time, click Save or Save this program to disk
1. 下載 Speech Platform Runtime 安裝
2. 下載 MSSpeech_TTS_zh-TW_HanHan.msi 中文安裝
3. 下載 MSSpeech_SR_zh-TW_TELE 中文安裝
4. 下載SDK安裝
5. Console mode testing program

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// Add SpeechLib.DLL from COM component
using SpeechLib;

namespace Speech5
{
    class Program
    {
        static void Main(string[] args)
        {
            SpVoice 說 = new SpVoice();
            說.Speak("本專題運用DXStudio與VS 2010開發工具,建立視窗型的角色扮演應用程式,除整理DXStudio可運用的場景、人物、物件等元件,以DXStudio編輯器,自行規劃場景與加入人物,綜合運用javascript與C#程式,開發遊戲所需之程式模組");
            說.Speak("This is a test for English speaking.", SpeechVoiceSpeakFlags.SVSFDefault);
        }
    }
}
測試OK!

2012年3月18日 星期日

Workflow-(i)

Hello world for workflow:
1. There are four templates for workflow applications
2. Hello world : WorkflowConsoleApplication
Basic structure is almost same as C# console mode application
namespace/class/Main

namespace WorkflowConsoleApplication2
{

    class Program
    {
        static void Main(string[] args)
        {
            WorkflowInvoker.Invoke(new Workflow1());
        }
    }
}
One more file in the project
Workflow1.xaml
2-1 the graphic form 
2-2 tag form
2-3 說明:

主程式進入點,由Workflow1.xaml類別建置物件
 WorkflowInvoker.Invoke(new Workflow1()); 
Workflow1.xaml 類別可用圖形界面,建構活動

3. Workflow1.xaml 可以用C#建置
 static Activity wf = new Sequence()
        {
            Activities = {
                                new WriteLine()
                                {
                                   Text = "Before the 1 minute delay."
                                },
                                new Delay()
                                {
                                    Duration = TimeSpan.FromSeconds(20)
                                },
                                new WriteLine()
                                {
                                    Text = "After the 1 minute delay."
                                }
                              }
        };
        
        static void Main(string[] args)
        {
            WorkflowInvoker.Invoke(new Workflow1()); // Call WorkFlow1.xaml
            try
            {
                WorkflowInvoker.Invoke(wf, TimeSpan.FromSeconds(60)); // Based on static Activity to create.
            }
            catch (TimeoutException ex)
            {
                Console.WriteLine(ex.Message);
            }


        }




2012年3月1日 星期四

Convert Powerpoint to images

1. Add reference

// Add Microsoft.Office.Iterop.PowerPoint v 14.0.0.0 (@NET)
// Add Microsoft Office 14.0 Object Library (@COM)
using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
2. Prepare myppt.pptx in debug or release folder
3. ConsoleMode program (Open vs2010 by administrator role)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// Add Micorsoft.Office.Iterop.PowerPoint v 14.0.0.0
using Microsoft.Office.Core;
using Microsoft.Office.Interop.PowerPoint;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            ApplicationClass ppt = new ApplicationClass();
            Presentation pptPresentation = ppt.Presentations.Open(@"E:\Working\pptimage\ConsoleApplication1\ConsoleApplication1\bin\Debug\myppt.pptx", MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
            for (int i = 1; i <= pptPresentation.Slides.Count ; i++)
            {
                pptPresentation.Slides[i].Export(@"E:\Working\pptimage\ConsoleApplication1\ConsoleApplication1\bin\Debug\slide" + i.ToString() + ".jpg", "jpg", 320, 240);
            }
           
        }
    }
}

4. Change both of  properties in
    Microsoft.Office.Iterop.PowerPoint v 14.0.0.0 (@NET)
    Microsoft Office 14.0 Object Library (@COM)
    Embed Interop Type -> False


5. Note: 1. The default directory of Slides[].Export is My Document
              2. It seems not to work without excuted by administrator role.


2012年2月29日 星期三

WPF 3D - 1 : Rotating Sphere

1. Add Ref: Primitive3DSurfaces.DLL
2. Add
     xmlns:my="clr-namespace:Primitive3DSurfaces;assembly=Primitive3DSurfaces"
3.

<Grid>
        <Grid.Background>
            <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                <LinearGradientBrush.GradientStops>
                    <GradientStop Color="Black" Offset="0"/>
                    <GradientStop Color="DarkBlue" Offset="1"/>
                </LinearGradientBrush.GradientStops>
            </LinearGradientBrush>
        </Grid.Background>
        <Viewport3D Grid.Column="0" Grid.Row="0">
            <Viewport3D.Camera>
                <PerspectiveCamera Position="0,0,-8" UpDirection="0,1,0" LookDirection="0,0,1" FieldOfView="45" NearPlaneDistance="0.125"/>
            </Viewport3D.Camera>
            <Viewport3D.Children>
                <ModelVisual3D>
                    <ModelVisual3D.Content>
                        <DirectionalLight Color="White" Direction="0,0,1" />
                    </ModelVisual3D.Content>
                </ModelVisual3D>
                <ModelVisual3D>
                    <ModelVisual3D.Transform>
                        <RotateTransform3D>
                            <RotateTransform3D.Rotation>
                                <AxisAngleRotation3D  x:Name="rotation" Angle="0" Axis="0,1,0" />
                            </RotateTransform3D.Rotation>
                        </RotateTransform3D>
                    </ModelVisual3D.Transform>
                    <my:Sphere3D>
                        <ModelVisual3D.Transform>
                            <TranslateTransform3D OffsetX="0" OffsetY="0" OffsetZ="0"  />
                        </ModelVisual3D.Transform>
                        <my:Sphere3D.Material>
                            <DiffuseMaterial>
                                <DiffuseMaterial.Brush>
                                    <ImageBrush ImageSource="earthspec1k.jpg" />
                                </DiffuseMaterial.Brush>

                            </DiffuseMaterial>
                        </my:Sphere3D.Material>
                    </my:Sphere3D>
                 
                </ModelVisual3D>
            </Viewport3D.Children>
        </Viewport3D>
    </Grid>
4. Add storyboard

<Window.Triggers>
    <EventTrigger RoutedEvent="Window.Loaded" >
      <BeginStoryboard>
        <Storyboard Name="myStoryBoard">
          <DoubleAnimation
            Storyboard.TargetName="rotation"
            Storyboard.TargetProperty="Angle"
            From="0" To="360" Duration="0:0:10" RepeatBehavior="Forever"/>
        </Storyboard>
      </BeginStoryboard>
    </EventTrigger>
  </Window.Triggers>
5. 

5. VS2010CS範例下載