Exemple #1
0
        private void PlayForm_Load(object sender, EventArgs e)
        {
            screencastData = ScreencastData.DeSerializeFrom(new FileStream(Path.Combine(Form1.SaveFolder, "zcast.xml"), FileMode.Open));
            screencastData.FrameInfos.Sort((x, y) => x.FrameNumber - y.FrameNumber);

            FormBorderStyle = FormBorderStyle.None;
            WindowState = FormWindowState.Maximized;
            //TopMost = true;

            Paint += new PaintEventHandler(PlayForm_Paint);

            Timer timer = new Timer();
            timer.Interval = screencastData.DelayBetweenFrames;
            timer.Tick += new EventHandler(timer_Tick);
            timer.Start();

            reconstructed = new Bitmap(screencastData.Width, screencastData.Height, PixelFormat.Format32bppArgb);
            g = Graphics.FromImage(reconstructed);
        }
Exemple #2
0
        private void btnCapture_Click(object sender, EventArgs e)
        {
            lock (btnCapture)
            {
                if (capturing)
                {
                    btnCapture.Text = "Start capturing";
                    stopCapture = true;
                    return;
                }

                btnCapture.Text = "Stop capture";
                capturing = true;
            }

            Stopwatch timer = new Stopwatch();
            Stopwatch timer2 = new Stopwatch();

            Bitmap bmpPrev = null;

            double last = Now();
            double betweenFrames = interval;

            timer.Start();
            ScreencastData screencastData = new ScreencastData();
            screencastData.Width = resX;
            screencastData.Height = resY;
            screencastData.DelayBetweenFrames = interval;

            //for (int i = 1; i <= nImages; i++)
            int frameNumber = 0;
            while(true)
            {
                if (stopCapture)
                {
                    stopCapture = false;
                    capturing = false;

                    timer.Stop();
                    label.Text = timer.Elapsed.Seconds + " s";

                    using (FileStream stream = new FileStream(Path.Combine(SaveFolder, "zcast.xml"), FileMode.Create))
                    {
                        screencastData.SerializeTo(stream);
                    }
                    return;
                }
                frameNumber++;

                IntPtr desktopWindow = NativeMethods.GetDesktopWindow();
                timer2.Reset();
                timer2.Start();
                Bitmap bmp = CaptureRectangle(desktopWindow, new Rectangle(0, 0, resX, resY));
                Debug.WriteLine("capture rectangle: " + timer2.ElapsedMilliseconds + "ms");
                //bmp.Save(@"C:\Users\Nicolas\Documents\test" + i + ".png");

                WaitCallback callBack = new WaitCallback(ComputeDiffJob);
                ThreadPool.QueueUserWorkItem(callBack, new ComputeDiffWork()
                {
                    BmpPrev = bmpPrev,
                    BmpCur = (Bitmap)bmp.Clone(),
                    FileName = "zcast" + frameNumber.ToString(),
                    ScreencastData = screencastData,
                    FrameNumber = frameNumber - 1,
                    EncodingQuality = (int)udQuality.Value
                });

                bmpPrev = bmp;
                label.Text = "" + frameNumber;
                Application.DoEvents();

                double now = Now();
                double nextFrameTime = last + betweenFrames;
                double remaining = nextFrameTime - now;
                if (remaining > 0)
                {
                    txtLog.AppendText("frame " + frameNumber + ": sleeping " + (remaining) + "ms\n");
                    while ((int)remaining > 1)
                    {
                        //txtLog.AppendText(Thread.CurrentThread.ManagedThreadId.ToString());
                        System.Threading.Thread.Sleep((int)remaining);
                        now = Now();
                        remaining = nextFrameTime - now;
                    }
                }
                else
                {
                    txtLog.AppendText(String.Format("Missed frame {0} by {1:f2}ms\n", frameNumber, -remaining));
                }
                last = now;
            }

            /*form.WindowState = FormWindowState.Maximized;
            form.FormBorderStyle = FormBorderStyle.None;
            form.TopMost = true;

            form.Paint += new PaintEventHandler(form_Paint);
            Bitmap reconstructed = new Bitmap(800, 600, PixelFormat.Format32bppArgb);
            Graphics g = Graphics.FromImage(reconstructed);
            for (int i = 1; i <= 1000; i++)
            {
                Bitmap bmp = new Bitmap(@"C:\Users\Nicolas\Documents\AAA\" + i + ".png");
                g.DrawImage(bmp, 0, 0, new Rectangle(0, 0, 800, 600), GraphicsUnit.Pixel);
                reconstructed.Save(@"C:\Users\Nicolas\Documents\AAA\reconstructed " + i + ".png");
                label.Text = "reconstructing: " + i;
                Application.DoEvents();
            }*/
        }