Skip to main content
A newer version of this page is available. .

CameraControl Class

Displays a video stream captured from a video input device, such as a webcam.

Namespace: DevExpress.XtraEditors.Camera

Assembly: DevExpress.XtraEditors.v17.2.dll

Declaration

[ToolboxTabName("DX.17.2: Common Controls")]
[ToolboxBitmap(typeof(ToolboxIconsRootNS), "CameraControl")]
public class CameraControl :
    BaseStyleControl,
    ICameraDeviceClient,
    IContextItemCollectionOptionsOwner,
    IContextItemCollectionOwner

Remarks

The CameraControl object represents a control that displays a video steam from a video capture device, such as a webcam, and provides an end-user with the capability to operate the device and adjust the video qualities. In the figure below, you can see the CameraControl displayed in the Take Picture dialog.

TakePictureDialog

In the top far corner, the CameraControl displays the predefined Settings context button. The visibility of this button is controlled by the CameraControl.ShowSettingsButton property. This button, when clicked, invokes the built-in Camera Settings panel, which allows an end-user to select the active device, adjust the resolution, contrast, brightness and saturation, or reset these settings to their defaults. See the figure below.

CameraControl_CameraSettings

In code, you can invoke this panel by calling the CameraControl.ShowSettingsForm method.

The CameraControl automatically detects video capture devices. By default, the control uses the first found device. At run time, the Camera Settings panel allows an end-user to select the device from which to capture the video stream. In code, for this purpose, use the CameraControl.Device property. To get the list of available devices, call the CameraControl.GetDevices static method.

The CameraControl allows you to operate the selected device — start or stop the video stream display, and take snapshots. To begin to capture and display a video, call the CameraControl.Start method. This method’s overloads allow you to start capturing video from the currently selected device, or specify a particular device. However, when the control is displayed onscreen for the first time, it automatically starts to display the video stream captured from the default device. To prevent this, set the CameraControl.AutoStartDefaultDevice property to false.

To get the video frame currently displayed by the control, call the CameraControl.TakeSnapshot method. This method returns a bitmap image that uses the 32 bit format to store color data. When you need to terminate capturing video, call the CameraControl.Stop method.

Also, the CameraControl provides you with the capability to adjust the video qualities on video capture devices. Typically, video capture devices support the brightness, contrast, hue, saturation, gamma, and sharpness properties. The availability of a video quality setting, as well as the extreme and default values, depends on a particular video capture device. At run time, an end-user can invoke the Camera Settings panel to adjust the video properties on available devices. In code, you can get access to the video properties on a currently selected device through the CameraControl.VideoSettings property.

Note

The video property values are held by the device itself. Thus, changing property values using the CameraControl may affect the quality of videos captured in other applications.

In addition to the Settings button, the CameraControl allows you to display custom context buttons and provide your end-users with custom functionality. The CameraControl.ContextButtons property provides access to the collection of context buttons displayed in the CameraControl. By default, the context buttons are hidden from view and seamlessly appear when the control is hovered over with the mouse pointer. However, the CameraControl.ContextButtonOptions property provides you with the capability to adjust the appearance and behavior of the context buttons. To respond to a context button click, handle the CameraControl.ContextButtonClick event. To learn more about context buttons, see the ContextItem base class.

Take Picture Dialog

The CameraControl is embedded in the Take Picture dialog (the DevExpress.XtraEditors.Camera.TakePictureDialog object) that can be used in your application to take a picture from an end-user’s webcam and get the resulting image. To show this dialog, call the TakePictureDialog.ShowDialog method. When this dialog is invoked, it automatically shows the video stream from the default webcam. An end-user can take a snapshot, and save it, or take another. See the figure below.

TakePictureDialog

When an end-user clicks the Save or Cancel button, the dialog closes and the TakePictureDialog.ShowDialog method returns the corresponding dialog result. If the Save button was clicked, the TakePictureDialog.Image property contains the taken snapshot. The code snippet below shows how to show the dialog and save the snapshot 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");
}
See Also