C# 摄像头拍照完整实例

2021-04-10 22:27

阅读:687

标签:sts   ogre   dialog   反转   result   bit   选择   sage   created   

 /// 
        /// 连接摄像头
        /// 
        /// 
        /// 
        private void button3_Click(object sender, EventArgs e)
        {
            CameraConn();
        }
 /// 
        /// 拍照
        /// 
        /// 
        /// 
        private void button6_Click_1(object sender, EventArgs e)
        {

            string RYID = txt_RYID.Text.ToString();
            if (RYID == null || RYID == "")
            {
                MessageBox.Show("请选择人员");
                return;
            }
            if (MessageBox.Show("确定是该人员:" + txt_XM.Text.ToString(), "提示", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }
            if (videoSourcePlayer.IsRunning)
                {
                  string path = System.Environment.CurrentDirectory+"\\摄像头照片\\";
                  BitmapSource bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                  videoSourcePlayer.GetCurrentVideoFrame().GetHbitmap(),
                  IntPtr.Zero,
                  Int32Rect.Empty,
                  BitmapSizeOptions.FromEmptyOptions());
                  PngBitmapEncoder pE = new PngBitmapEncoder();
                  pE.Frames.Add(BitmapFrame.Create(bitmapSource));
                  picName = path + txt_XM.Text.ToString() +txt_RYID.Text.ToString()+ ".jpg";
                  picName2 = path + txt_XM.Text.ToString() + txt_RYID.Text.ToString() +"2.jpg";
                  if (!Directory.Exists(path))
                {
                      Directory.CreateDirectory(path);
                 }
                  if (File.Exists(picName))
                  {
                      File.Delete(picName);
                  }
                  if (File.Exists(picName2))
                  {
                      File.Delete(picName2);
                  }
                  using (Stream stream = File.Create(picName))
                  {
                      pE.Save(stream);
                  }
                  ///将图片左右反转
                  if (File.Exists(picName))
                  {
                      Bitmap bmp = new Bitmap(picName);
                      bmp= RevPic(bmp, 1280, 720);
                      bmp.Save(picName2, System.Drawing.Imaging.ImageFormat.Jpeg);
                  }
                    
                  MessageBox.Show("拍照成功");
                 
                }
        }
//关闭摄像头
private void button8_Click(object sender, EventArgs e)
        {
            videoSourcePlayer.SignalToStop();
            videoSourcePlayer.WaitForStop();
        }

 

C# 摄像头拍照完整实例

标签:sts   ogre   dialog   反转   result   bit   选择   sage   created   

原文地址:https://www.cnblogs.com/zengwen/p/9035507.html


评论


亲,登录后才可以留言!