码迷,mamicode.com
首页 > Windows程序 > 详细

C# 摄像头拍照完整实例

时间:2018-05-14 13:15:58      阅读:545      评论:0      收藏:0      [点我收藏+]

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

 /// <summary>
        /// 连接摄像头
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            CameraConn();
        }
 /// <summary>
        /// 拍照
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!