////// 连接摄像头 /// /// /// 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(); }