Camera Control
- 3 minutes to read
The CameraControl displays a video stream from a video capture device (a webcam) and allows you to save snapshots.
- Select a Capture Device
- Settings Dialog
- Operate the Video Stream and Take Snapshots
- “Take Picture” Dialog
Select a Capture Device
The Camera Control automatically detects video recording devices and starts streaming data. To disable this feature, disable the CameraControl.AutoStartDefaultDevice property.
The Camera Control creates a CameraDevice object for each recording device. The active webcam’s CameraDevice object is assigned to the CameraControl.Device property. To manually change the active camera, do the following:
- Call the static CameraControl.GetDevices method to obtain the list of available device info objects (the CameraDeviceInfo class objects);
- Call the static CameraControl.GetDevice method to retrieve a CameraDevice object by its CameraDeviceInfo object;
- Assign the CameraDevice object to the CameraControl.Device property or pass it to the CameraControl.Start method as a parameter.
The example below illustrates how to switch to the first available Logitech webcam manually.
private void button_Click(object sender, EventArgs e) {
CameraDeviceInfo a4camInfo = CameraControl.GetDevices().Find(x => x.Name.Contains("Logitech"));
cameraControl1.Start(CameraControl.GetDevice(a4camInfo));
}
Note
A Camera Control cannot receive data from a webcam which is already streaming to another control or “Take Picture” dialog.
Settings Dialog
If the CameraControl.ShowSettingsButton property is enabled, the Camera Control shows a Settings button when a user hovers the mouse pointer over the client area.
Clicking this button invokes the Camera Settings dialog that allows you to choose the active camera and adjust video settings.
To invoke this dialog from code, call the CameraControl.ShowSettingsForm method. You can also access the current webcam’s video quality settings through the CameraControl.VideoSettings property.
Important
- Video settings are stored in the recording device. Changing these settings in the Camera Control’s Settings dialog can affect the quality of videos captured in other applications.
- The type of webcam determines the video quality settings (and their maximum\minimum values) available in the Settings Dialog.
Operate the Video Stream and Take Snapshots
- CameraControl.Start - starts transmitting video data from the selected webcam.
CameraControl.Stop - terminates streaming. A Camera Control that streams nothing displays the following message:
CameraControl.TakeSnapshot - saves the displayed frame as a 32-bit Bitmap object. Call the Bitmap.Save() method to save this bitmap to a local storage or stream.
private void simpleButton1_Click(object sender, EventArgs e) { string filePath = Path.Combine(@"D:\Snapshots\", DateTime.Now.Year.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Day.ToString() + "--" + DateTime.Now.Hour.ToString() + "-" + DateTime.Now.Minute.ToString() + "-" + DateTime.Now.Second.ToString() + ".jpg"); cameraControl1.TakeSnapshot().Save(filePath, ImageFormat.Jpeg); }
“Take Picture” Dialog
If you need the Camera Control to take pictures, use the Take Picture Dialog instead. This is a modal dialog with an embedded Camera Control and the “Capture”_“Save”\“Cancel”_ buttons.
To invoke this dialog from code, create a new DevExpress.XtraEditors.Camera.TakePictureDialog class instance and call its ShowDialog method. The dialog returns the captured bitmap when a user clicks “Save”.