Example #1
0
        private void OpenCapture()
        {
            int    intWidth  = this.panelCamera.Width;
            int    intHeight = this.panelCamera.Height;
            int    intDevice = 0;
            string refDevice = intDevice.ToString();

            //创建视频窗口并得到句柄
            hHwnd = CameraForm.capCreateCaptureWindowA(ref refDevice, 1342177280, 0, 0, 640, 480, this.panelCamera.Handle.ToInt32(), 0);
            if (CameraForm.SendMessage(hHwnd, 0x40a, intDevice, 0) > 0)
            {                                                     //0x435,0x434,0x432是根据前面句柄而随即定义的参数
                CameraForm.SendMessage(this.hHwnd, 0x435, -1, 0); //该函数将指定的消息发送到一个或多个窗口
                CameraForm.SendMessage(this.hHwnd, 0x434, 0x42, 0);
                CameraForm.SendMessage(this.hHwnd, 0x432, -1, 0);
                CameraForm.SetWindowPos(this.hHwnd, 1, 0, 0, intWidth, intHeight, 6);
            }
            else
            {
                CameraForm.DestroyWindow(this.hHwnd);//销毁指定的窗口。
            }
        }
Example #2
0
 private void btnScreenshot_Click(object sender, EventArgs e)
 {
     try
     {
         CameraForm.SendMessage(this.hHwnd, 0x41e, 0, 0);
         IDataObject obj1 = Clipboard.GetDataObject();
         if (obj1.GetDataPresent(typeof(Bitmap)))
         {
             Image          image1          = (Image)obj1.GetData(typeof(Bitmap));
             SaveFileDialog SaveFileDialog1 = new SaveFileDialog();
             SaveFileDialog1.FileName = DateTime.Now.ToString("yyyyMMddhhmmss");//用当前的时间的字符串作为图片的名字避免重复
             SaveFileDialog1.Filter   = "Image Files(*.JPG;*.GIF)|*.JPG;*.GIF|All files (*.*)|*.*";
             if (SaveFileDialog1.ShowDialog() == DialogResult.OK)
             {
                 image1.Save(SaveFileDialog1.FileName, ImageFormat.Bmp);
             }
         }
     }
     catch
     {
     }
 }
Example #3
0
 private void btnCamera_Click(object sender, EventArgs e)
 {
     CameraForm cameraForm = new CameraForm();
     cameraForm.Show();
 }
Example #4
0
 private void btnStop_Click(object sender, EventArgs e)
 {
     //停止视频注销视频句柄
     CameraForm.SendMessage(this.hHwnd, 0x40b, 0, 0);
     CameraForm.DestroyWindow(this.hHwnd);
 }