| | |
| | | } |
| | | |
| | | IntPtr displayHandle = onlinePictureBox.Handle; |
| | | if (brand == CameraBrand.LBCamera) |
| | | { |
| | | onlinePictureBox.Visible = false; |
| | | displayHandle = this.panel_Picture.Handle; |
| | | } |
| | | else |
| | | { |
| | | onlinePictureBox.Visible = true; |
| | | } |
| | | |
| | | if (cmbSN.Items.Count > 0 && camera.InitDevice(cmbSN.Text.ToString(), displayHandle)) |
| | | { |
| | |
| | | /// <param name="image"></param> |
| | | private void GetImageBllComplete(object sender, CameraEventArgs e) |
| | | { |
| | | // 对于LBCamera(SDK自动显示模式),Bitmap为null,我们只需要统计 |
| | | if (camera.Brand == CameraBrand.LBCamera) |
| | | { |
| | | if (e is LBCameraEventArgs args && args.IsComplete) |
| | | { |
| | | total.iImageCount++; |
| | | // 不需要更新onlinePictureBox.Image,SDK会自动显示 |
| | | } |
| | | return; |
| | | } |
| | | |
| | | // 对于2D相机(手动处理模式) |
| | | // 对于2D相机(手动处理模式)和现在的LBCamera(手动处理模式) |
| | | if (e.Bitmap == null) |
| | | return; |
| | | |
| | |
| | | |
| | | if (success) |
| | | { |
| | | // 对于LBCamera(SDK自动显示模式),等待采集完成即可 |
| | | // 对于2D相机,等待Bitmap事件 |
| | | if (camera.Brand == CameraBrand.LBCamera) |
| | | { |
| | | // SDK自动显示模式下,等待采集完成 |
| | | using (AutoResetEvent waitHandle = new AutoResetEvent(false)) |
| | | { |
| | | bool captured = false; |
| | | EventHandler<CameraEventArgs> handler = (s, evt) => |
| | | { |
| | | if (evt is LBCameraEventArgs args && args.IsComplete) |
| | | { |
| | | captured = true; |
| | | waitHandle.Set(); |
| | | } |
| | | }; |
| | | |
| | | camera.ImageGrabbed += handler; |
| | | try |
| | | { |
| | | // 等待5秒超时 |
| | | if (waitHandle.WaitOne(5000)) |
| | | { |
| | | // SDK自动显示模式,不返回Bitmap |
| | | // 但采集已完成 |
| | | } |
| | | this.BeginInvoke(new Action(() => |
| | | { |
| | | this.lblCapTime.Text = $"{(DateTime.Now - StartTime).TotalMilliseconds}ms"; |
| | | })); |
| | | } |
| | | finally |
| | | { |
| | | camera.ImageGrabbed -= handler; |
| | | camera.StopGrabbing(); |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | // 对于2D相机,等待图像数据 |
| | | // 等待图像数据 |
| | | using (AutoResetEvent waitHandle = new AutoResetEvent(false)) |
| | | { |
| | | Bitmap captured = null; |
| | | EventHandler<CameraEventArgs> handler = (s, evt) => |
| | | { |
| | | // 对于2D相机,直接接收图像 |
| | | if (!(evt is LBCameraEventArgs) && evt.Bitmap != null) |
| | | if (evt.Bitmap != null) |
| | | { |
| | | captured = evt.Bitmap.Clone() as Bitmap; |
| | | waitHandle.Set(); |
| | |
| | | this.lblCapTime.Text = "-1ms"; |
| | | } |
| | | })); |
| | | } |
| | | } |
| | | else |
| | | { |