-api-id | -api-type |
---|---|
T:Windows.UI.Xaml.Controls.CaptureElement |
winrt class |
Renders a stream from a capture device, such as a camera or webcam. CaptureElement is used in conjunction with the Windows.Media.Capture.MediaCapture API, and must be hooked up in the code behind.
<CaptureElement .../>
CaptureElement is used in conjunction with the Windows.Media.Capture.MediaCapture API. Make sure your project has specified device capabilities for Webcam and Microphone to use this API. For more info on how to use CaptureElement, see Capture photos and video with MediaCapture.
Use the MediaCapture object to control the stream and set options on the capture device. The CaptureElement is the UI portion of the stream that is associated with the MediaCapture.
You can use at most one CaptureElement to render a stream from a single capture device.
Note
If your app manually sets the size of the CaptureElement control, you must make sure that the dimensions of the control do not exceed the device's native display resolution.
Here's some code that shows how to capture video from a camera with a MediaCapture control and display the preview with the CaptureElement.
<StackPanel>
<CaptureElement x:Name="myCaptureElement"
Width="320" Height="240"/>
<Button Click="Button_Click">Click me to see a preview</Button>
</StackPanel>
// You must specify capabilities for Webcam and Microphone in your
// app manifest for this code to work.
private async void Button_Click(object sender, RoutedEventArgs e)
{
// Using Windows.Media.Capture.MediaCapture APIs
// to stream from webcam
MediaCapture mediaCaptureMgr = new MediaCapture();
await mediaCaptureMgr.InitializeAsync();
// Start capture preview.
myCaptureElement.Source = mediaCaptureMgr;
await mediaCaptureMgr.StartPreviewAsync();
}
FrameworkElement, MediaCapture, Capture photos and video with MediaCapture, Media capture sample, Camera capture UI sample, Call asynchronous APIs in C# or Visual Basic