Ejemplo n.º 1
0
        private void buttonCapture_Click(object sender, EventArgs e)
        {
            this.WindowState = FormWindowState.Minimized;
            ScreenCapture sc = new ScreenCapture();
            string fn = String.Format(textInputMask.Text, 0);
            string dir = Path.GetDirectoryName(fn);
            Directory.CreateDirectory(dir);
            dir += "\\capturelog.txt";
            StreamWriter log = new StreamWriter(new FileStream(dir, FileMode.Create));

            Image im;
            Stopwatch sw = new Stopwatch();
            Thread.Sleep(200);

            int frameNo = 0;
            long msCurrent;       // time of the next capture in milliseconds
            long msTotal = (long)((double)numericDuration.Value * 1000.0);

            sw.Reset();
            sw.Start();
            do
            {
                im = sc.CaptureScreen();
                fn = String.Format(textInputMask.Text, frameNo++);
                im.Save(fn, ImageFormat.Png);
                msCurrent = (long)(frameNo * 1000.0 / (double)numericFps.Value);
                long msSleep = msCurrent - sw.ElapsedMilliseconds;
                if (msSleep > 0)
                {
                    log.WriteLine("Frame {0:0000}: sleeping {1} ms", frameNo, msSleep);
                    Thread.Sleep((int)msSleep);
                }
                else
                    log.WriteLine("Frame {0:0000}: busy! ({1} ms)", frameNo, msSleep);
            }
            while (sw.ElapsedMilliseconds < msTotal);
            labelSpeed.Text = String.Format("Captured {0} frames in {1:f} s!", frameNo, (float)(sw.ElapsedMilliseconds * 0.001));
            log.Close();
            sw.Stop();

            this.WindowState = FormWindowState.Normal;
        }
        public static void Main()
        {
            while(true)
            {
            Socket s = null;
            Socket client;

            s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            s.Bind(new IPEndPoint(IPAddress.Any, 9988));
            s.Listen(1);

            client = s.Accept();

            ScreenCapture sc = new ScreenCapture();
            Image img = sc.CaptureScreen();
            img.Save(new NetworkStream(client), ImageFormat.Jpeg);
            Thread.Sleep(100);

            client.Close();
            s.Close();
            }
        }
Ejemplo n.º 3
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                ScreenCapture sc = new ScreenCapture();
                // capture entire screen, and save it to a file
                Image img = sc.CaptureWindow(this.Handle);
                if (partToolStripMenuItem.Checked)
                {
                    img = sc.CaptureWindow(this.Handle,xstart,ystart,iwidth,iheight);
                }
                if (!thisToolStripMenuItem.Checked)
                {
                    if (partToolStripMenuItem.Checked)
                    {
                        img = sc.CaptureScreen(xstart, ystart, iwidth, iheight);
                    }
                    else
                    {
                        img = sc.CaptureScreen();
                    }
                }
                
                if (saveToolStripMenuItem.Checked)
                {
                    string strpicpath = "";
                    if (Directory.Exists(picpath) || (picpath.IndexOf(@":\") != -1))
                    {
                        strpicpath = picpath;
                    }
                    else if (picpath.IndexOf(@":\") == -1)
                    {
                        strpicpath = (new FileInfo(Application.ExecutablePath)).DirectoryName + "\\" + picpath;
                    }
                    if (!Directory.Exists(strpicpath))
                    {
                        Directory.CreateDirectory(strpicpath);
                    }
                    img.Save(strpicpath + "\\Cap_" + System.DateTime.Now.Ticks.ToString() + "." + toolStripComboBox1.Text, getImageFormat(toolStripComboBox1.Text));
                }
                if (showToolStripMenuItem.Checked)
                {
                    // display image in a Picture control named imageDisplay
                    this.pictureBox1.Image = img;
                    if (partToolStripMenuItem.Checked && sameSizeToolStripMenuItem.Checked)
                    {
                        this.Width = pictureBox1.Width + 10;
                        this.Height = pictureBox1.Height + (statusStrip1.Height*2) + 10;
                    }
                }
                
                if (server.Pending())
                {
                    N.Sockets.TcpClient client = server.AcceptTcpClient();
                    htClients.Add(client, client);

                    sendImgToClient(client, img);

                }
                if (htClients.Count > 0)
                {
                    toolStripStatusLabel1.Text = "Connection made (" + htClients.Count.ToString() + ")";
                }
                else
                {
                    toolStripStatusLabel1.Text = "server started";
                }
                
                foreach (object k in htClients.Keys)
                {
                    N.Sockets.TcpClient client = (N.Sockets.TcpClient)k;
                    if (client.Connected)
                    {
                        sendImgToClient(client,img);
                    }
                    else
                    {
                        client.Client.Disconnect(false);
                        htClients.Remove(k);
                    }
                }
                
                GC.Collect();
            }
            catch(Exception ex)
            {
                toolStripStatusLabel1.Text += ex.Message;
                
            }
            pictureBox1.Refresh();
            this.Refresh();

        }
Ejemplo n.º 4
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                ScreenCapture sc = new ScreenCapture();
                // capture entire screen, and save it to a file
                Image img = sc.CaptureWindow(this.Handle);
                if (partToolStripMenuItem.Checked)
                {
                    img = sc.CaptureWindow(this.Handle, xstart, ystart, iwidth, iheight);
                }
                if (!thisToolStripMenuItem.Checked)
                {
                    if (partToolStripMenuItem.Checked)
                    {
                        img = sc.CaptureScreen(xstart, ystart, iwidth, iheight);
                    }
                    else
                    {
                        img = sc.CaptureScreen();
                    }
                }

                if (saveToolStripMenuItem.Checked)
                {
                    string strpicpath = "";
                    if (Directory.Exists(picpath) || (picpath.IndexOf(@":\") != -1))
                    {
                        strpicpath = picpath;
                    }
                    else if (picpath.IndexOf(@":\") == -1)
                    {
                        strpicpath = (new FileInfo(Application.ExecutablePath)).DirectoryName + "\\" + picpath;
                    }
                    if (!Directory.Exists(strpicpath))
                    {
                        Directory.CreateDirectory(strpicpath);
                    }
                    img.Save(strpicpath + "\\Cap_" + System.DateTime.Now.Ticks.ToString() + "." + toolStripComboBox1.Text, getImageFormat(toolStripComboBox1.Text));
                }
                if (showToolStripMenuItem.Checked)
                {
                    // display image in a Picture control named imageDisplay
                    this.pictureBox1.Image = img;
                    if (partToolStripMenuItem.Checked && sameSizeToolStripMenuItem.Checked)
                    {
                        this.Width  = pictureBox1.Width + 10;
                        this.Height = pictureBox1.Height + (statusStrip1.Height * 2) + 10;
                    }
                }

                if (server.Pending())
                {
                    N.Sockets.TcpClient client = server.AcceptTcpClient();
                    htClients.Add(client, client);

                    sendImgToClient(client, img);
                }
                if (htClients.Count > 0)
                {
                    toolStripStatusLabel1.Text = "Connection made (" + htClients.Count.ToString() + ")";
                }
                else
                {
                    toolStripStatusLabel1.Text = "server started";
                }

                foreach (object k in htClients.Keys)
                {
                    N.Sockets.TcpClient client = (N.Sockets.TcpClient)k;
                    if (client.Connected)
                    {
                        sendImgToClient(client, img);
                    }
                    else
                    {
                        client.Client.Disconnect(false);
                        htClients.Remove(k);
                    }
                }

                GC.Collect();
            }
            catch (Exception ex)
            {
                toolStripStatusLabel1.Text += ex.Message;
            }
            pictureBox1.Refresh();
            this.Refresh();
        }