private void btnCamera_Click(object sender, EventArgs e) { DeleteCapture(); var hEvent = IntPtr.Zero; int index = comboBoxCamera.SelectedIndex; camera = cameraDevice.Create(index, this.pictureBox1, hEvent); MethodInvoker invoked_method = (() => { if (null != pictureBox1.Image) { pictureBox1.Image.Dispose(); } if (null != camera) { var img = camera.SnapShot().ToBMP(); this.pictureBox1.Image = img; } }); unsafe { camera.SampleEvent = (time, buf, size) => { BeginInvoke((MethodInvoker)invoked_method); }; } camera.ResetSampleEvent(); setSize(camera.Width, camera.Height); camera.Start(); }
private void btnCamera_Click(object sender, EventArgs e) { DeleteCapture(); var hEvent = IntPtr.Zero; int index = comboBoxCamera.SelectedIndex; camera = cameraDevice.Create(index, this.pictureBox1, hEvent); MethodInvoker invoked_method = (() => { if (null != pictureBox1.Image) pictureBox1.Image.Dispose(); if (null != camera) { var img = camera.SnapShot().ToBMP(); this.pictureBox1.Image = img; } }); unsafe { camera.SampleEvent = (time, buf, size) => { BeginInvoke((MethodInvoker)invoked_method); }; } camera.ResetSampleEvent(); setSize(camera.Width, camera.Height); camera.Start(); }