Ejemplo n.º 1
0
 private void button_1pic_Click(object sender, EventArgs e)
 {
     if (savePath != string.Empty)
     {
         if (videoSourcePlayer1.IsRunning)
         {
             Thread.Sleep(1200);
             SavePics.Click_button_1pic(DateTime.Now.ToString("yyyyMMddHHmmss0ffff"));
         }
         else
         {
             MessageBox.Show("摄像头没有运行!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     else
     {
         MessageBox.Show("未设置图片保存路径!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Ejemplo n.º 2
0
        private void button_openCamera_Click(object sender, EventArgs e)
        {
            if (videoSource != null)                  //先判断有木有视频来源
            {
                if (button_openCamera.Text == "打开相机") //打开相机
                {
                    //videoSource.DisplayPropertyPage(IntPtr.Zero);
                    videoSourcePlayer1.VideoSource = videoSource;
                    videoResolution = videoSource.VideoResolution;

                    //videoSourcePlayer1.NewFrame += new VideoSourcePlayer.NewFrameHandler(videoPlayerRotate_NewFrame);


                    videoSourcePlayer1.Start();
                    button_openCamera.BackColor = Color.Yellow;

                    button_openCamera.Text = "关闭相机";
                    // 开启帧率显示

                    frame_timer.Start();
                    frame_timer.Elapsed += new ElapsedEventHandler(FrameCount);
                    SavePics.SetVideoSourcePlayer(videoSourcePlayer1, button_multpic);
                }
                else // 关闭相机
                {
                    videoSource.SignalToStop();
                    videoSource.WaitForStop();
                    videoSource.Stop();
                    videoSourcePlayer1.SignalToStop();
                    videoSourcePlayer1.WaitForStop();
                    videoSourcePlayer1.Stop();
                    button_openCamera.Text      = "打开相机";
                    button_openCamera.BackColor = Color.White;
                    frame_timer.Stop();
                    frame_timer.Elapsed -= new ElapsedEventHandler(FrameCount);
                    label2.Text          = null;
                }
            }
            else
            {
                MessageBox.Show("未连接到相机,请检测相机!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Ejemplo n.º 3
0
        //private void videoPlayerRotate_NewFrame(object sender, ref Bitmap image)
        //{
        //    //Bitmap image = (Bitmap)eventArgs.Frame.Clone();
        //    //if (image != null)
        //    //{

        //    //    // RotateFlipType.Rotate90FlipNone;90度翻转

        //    //    //RotateFlipType.RotateNoneFlipX 按X轴翻转
        //    //    image.RotateFlip(RotateFlipType.RotateNoneFlipX);
        //    //}

        //    //eventArgs.Frame.RotateFlip(RotateFlipType.Rotate90FlipNone);
        //    image.RotateFlip(RotateFlipType.RotateNoneFlipX);
        //}

        static void ReceiveMessage()
        {
            while (true)
            {
                EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
                byte[]   data           = new byte[1024];
                int      length         = udpServer.ReceiveFrom(data, ref remoteEndPoint);//这个方法会把数据的来源(ip:port)放到第二个参数上
                string   message        = Encoding.UTF8.GetString(data, 0, length);
                //MessageBox.Show(message, "接收成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
                int message0 = message[0];
                if (message0 == 49)
                {
                    string receiveTime_1pic = message.Substring(1);
                    if (textBox2.Text == string.Empty)
                    {
                        MessageBox.Show("未设置图片保存路径!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        if (button_openCamera1.BackColor == Color.Yellow)
                        {
                            Thread.Sleep(1200);
                            SavePics.Click_button_1pic(receiveTime_1pic);
                        }
                        else
                        {
                            MessageBox.Show("摄像头没有运行!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
                else if (message0 == 50)
                {
                    string receiveTime_multpic = message.Substring(1);
                    if (textBox2.Text == string.Empty)
                    {
                        MessageBox.Show("未设置图片保存路径!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        if (button_openCamera1.BackColor == Color.Yellow)
                        {
                            Thread.Sleep(1200);
                            SavePics.Click_button_multpic(receiveTime_multpic);
                        }
                        else
                        {
                            MessageBox.Show("摄像头没有运行!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
                else if (message0 == 48)
                {
                    string savePath = message.Substring(1);
                    SavePics.SetPicFloder(savePath);
                    button_multpic1.Enabled = true;
                    button_1pic1.Enabled    = true;
                    textBox2.Text           = savePath;
                }
                if (message == "guanji")
                {
                    udpServer.Close();
                    Environment.Exit(0);
                }
            }
        }