2013年3月26日 星期二

Screen Capture By Thread

1. OS: Windows 7  x64
2. Tools: VS2010, Expression 4.0
3. Prepare a class for capturing scrren and save to outputpath

class BkScnCap
    {
        ScreenCaptureJob job;
        public BkScnCap()
        {
            job = new ScreenCaptureJob();
         
        }
        public void Record()
        {
            System.Drawing.Size monitorSize = SystemInformation.PrimaryMonitorSize;
            System.Drawing.Rectangle capRect = new System.Drawing.Rectangle(0, 0, monitorSize.Width, monitorSize.Height);
            job.CaptureRectangle = capRect;
            job.OutputPath = @"E:\output\ScreenCap";
            job.Start();
        }
        public void StopRecord()
        {
            job.Stop();
        }
    }
4. Make backgroud thread method in constructor, Click to start this thread and click the stop to end it.

public MainWindow()
        {
            InitializeComponent();
            oBkScnCap = new BkScnCap();
            oThread = new System.Threading.Thread(new System.Threading.ThreadStart(oBkScnCap.Record));
        }
        System.Threading.Thread oThread;
        BkScnCap oBkScnCap;
        private void 儲存影片_Click(object sender, RoutedEventArgs e)
        {
            oThread.Start();
        }

        private void 停止影片擷取_Click(object sender, RoutedEventArgs e)
        {
            oBkScnCap.StopRecord();
        }
5. Screen resolution issue

沒有留言:

張貼留言