windowsforms-114582-controls-and-libraries-editors-and-simple-controls-camera-control.md
The CameraControl displays a video stream from a video capture device (a webcam) and allows you to save snapshots.
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:
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));
}
Private Sub simpleButton1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim a4camInfo As CameraDeviceInfo = CameraControl.GetDevices().Find(Function(x) x.Name.Contains("Logitech"))
cameraControl1.Start(CameraControl.GetDevice(a4camInfo))
End Sub
Note
A Camera Control cannot receive data from a webcam that is already streaming to another control or “Take Picture” 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
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.
Use the Take Picture dialog to take pictures from an attached camera device in a modal dialog. This dialog contains an embedded Camera Control.
To invoke this dialog from code, create a TakePictureDialog class instance and call its ShowDialog method. The dialog returns the captured bitmap when a user clicks “Save”.
The following code shows a TakePictureDialog and then saves the captured image to a file.
using DevExpress.XtraEditors.Camera;
TakePictureDialog d = new TakePictureDialog();
if(d.ShowDialog() == System.Windows.Forms.DialogResult.OK){
Image i = d.Image;
i.Save("C:\\snapshot.bmp");
}
Imports DevExpress.XtraEditors.Camera
Dim d As New TakePictureDialog()
If d.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Dim i As Image = d.Image
i.Save("C:\snapshot.bmp")
End If
The Take Picture dialog saves the currently selected camera device and its resolution in the system registry when a user closes the dialog. These settings are reused the next time a user opens the dialog. If the system registry contains no information on the previously used camera device, the Take Picture dialog will use the default camera device (CameraControl.GetDefaultDevice).
To override the default camera device and resolution selection, use the TakePictureDialog.Device and TakePictureDialog.ResolutionMode properties.
The following example sets the maximum resolution for the selected camera device.
TakePictureDialog dialog = new TakePictureDialog();
dialog.ResolutionMode = ResolutionMode.Maximum;
dialog.ShowDialog();
Dim dialog As TakePictureDialog = New TakePictureDialog()
dialog.ResolutionMode = ResolutionMode.Maximum
dialog.ShowDialog()
The following events allow you to customize the dialog, camera device, resolution and captured image: