How to preview video from a webcam (Windows Store apps using C#/VB/C++ and XAML)
Roadmap: How does this topic relate to others? See:
This topic assumes that you know how to create a basic Windows Store app using C++, C#, or Visual Basic. For help creating your first app, see Create your first Windows Store app using C# or Visual Basic.
To enable webcam access, the app must include the Webcam DeviceCapability in the application manifest.
- In Microsoft Visual Studio, in Solution Explorer, open the designer for the application manifest by double-clicking the package.appxmanifest item
- Click Capabilities.
- Check the box for Webcam.
Create a CaptureElement in Extensible Application Markup Language (XAML).You will use this to render the video to the display.
This example instantiates a new MediaCapture object and calls InitializeAsync to initialize the MediaCapture object to the default settings. You can pass a MediaCaptureInitializationSettings object into InitializeAsync to set specific settings.
// Start capture preview. // capturePreview is a CaptureElement defined in XAML. capturePreview.Source = captureMgr; await captureMgr.StartPreviewAsync();
The full code for this example.
MediaCapture captureMgr = new MediaCapture(); await captureMgr.InitializeAsync(); // Start capture preview. // capturePreview is a CaptureElement defined in XAML. capturePreview.Source = captureMgr; await captureMgr.StartPreviewAsync();
- Roadmap for Windows Store apps using C# and Visual Basic
- Roadmap for Windows Store apps using C++
- Designing UX for apps
- Adding multimedia
- Media capture sample
- Camera capture UI sample
- Camera options UI sample
- Device enumeration sample
- Media extension sample
- Real-Time communication sample
- Quickstart: video and audio
- How to select audio tracks in different languages
- Other resources
- Supported audio and video formats
- Optimize media resources