Skip to content

Commit 6efc8b4

Browse files
committed
Draft of CameraCaptureUI how-to
1 parent 08443ad commit 6efc8b4

File tree

2 files changed

+80
-3
lines changed

2 files changed

+80
-3
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
title: Capture photos and video in a desktop app with the Windows built-in camera UI
3+
description: Learn how to capture photos and video using the camera UI built into Windows.
4+
ms.topic: article
5+
ms.date: 07/23/2024
6+
ms.author: drewbat
7+
author: drewbatgit
8+
ms.localizationpriority: medium
9+
#customer intent: As a developer, I want to access the camera in a Windows app using WinUI 3.
10+
---
11+
12+
# Capture photos and video in a desktop app with the Windows built-in camera UI
13+
14+
This article describes how to use the [CameraCaptureUI](/windows/windows-app-sdk/api/winrt/microsoft.windows.media.capture) class to capture photos or videos by using the camera UI built into Windows. This feature allows your app to get a user-captured photo or video with just a few lines of code.
15+
16+
If you want to provide your own camera UI, or if your scenario requires more robust, low-level control of the capture operation, then you should use the [MediaCapture](/uwp/api/windows.media.capture.mediacapture) class, and implement your own capture experience. For more information, see [Basic photo, video, and audio capture with MediaCapture](basic-photo-capture).
17+
18+
Note that the **CameraCaptureUI** class in the [Microsoft.Windows.Media.Capture](/windows/windows-app-sdk/api/winrt/microsoft.windows.media.capture) namespace is not supported for UWP apps. For information on using the UWP version of this feature, see [Capture photos and video in a UWP app with the Windows built-in camera UI](/windows/uwp/audio-video-camera/capture-photos-and-video-with-cameracaptureui)
19+
20+
Create a new instance of **CameraCaptureUI**, passing in the [AppWindow.Id](/windows/windows-app-sdk/api/winrt/microsoft.ui.windowing.appwindow.id) property of your app window. The [PhotoSettings](/windows/windows-app-sdk/api/winrt/microsoft.windows.media.capture.cameracaptureui.photosettings) property allows you to specify some constraints on the captured photo, including the file format and maximum resolution and whether UI allows the user to crop the photo after it's captured. The [VideoSettings](/windows/windows-app-sdk/api/winrt/microsoft.windows.media.capture.cameracaptureui.videosettings) property provides similar properties for video capture, such as the maximum resolution and duration and whether the UI allows the user to trip the video after it's captured.
21+
22+
Call [CaptureFileAsync](/windows/windows-app-sdk/api/winrt/microsoft.windows.media.capture.cameracaptureui.capturefileasync) to launch the camera capture UI asynchronously. Use one of the values from the [CameraCaptureUIMode](/windows/windows-app-sdk/api/winrt/microsoft.windows.media.capture.cameracaptureuimode) to specify whether the UI should allow photo capture, video capture, or both. When **CaptureFileAsync** completes, it will return a [StorageFile](/uwp/api/windows.storage.storagefile) file object containing the captured photo or video. If the returned object is null it means that either the user cancelled the capture operation or an error occurred.
23+
24+
### [C#](#tab/csharp)
25+
26+
```csharp
27+
var cameraCaptureUI = new CameraCaptureUI(this.AppWindow.Id);
28+
cameraCaptureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Png;
29+
cameraCaptureUI.PhotoSettings.AllowCropping = false;
30+
31+
// Capture a photo asynchronously
32+
StorageFile photo = await cameraCaptureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);
33+
34+
if (photo != null)
35+
{
36+
// Photo capture was successful
37+
} else
38+
{
39+
// Photo capture failed or was cancelled
40+
}
41+
CaptureVideo();
42+
}
43+
```
44+
45+
### [C++/WinRT](#tab/csharp)
46+
47+
```cpp
48+
// Get the WindowId for the window
49+
Microsoft::UI::WindowId windowId = this->AppWindow().Id();
50+
51+
// Initialize CameraCaptureUI with a window handle
52+
winrt::Microsoft::Windows::Media::Capture::CameraCaptureUI cameraUI(windowId);
53+
54+
// Configure Photo Settings
55+
cameraUI.PhotoSettings().Format(CameraCaptureUIPhotoFormat::Png);
56+
cameraUI.PhotoSettings().AllowCropping(false);
57+
58+
// Capture a photo asynchronously
59+
auto photo = co_await cameraUI.CaptureFileAsync(CameraCaptureUIMode::Photo);
60+
61+
62+
if (photo != nullptr)
63+
{
64+
// Photo capture was successful
65+
}
66+
else
67+
{
68+
// Photo capture failed or was cancelled
69+
}
70+
```
71+
72+
---
73+
74+

uwp/audio-video-camera/capture-photos-and-video-with-cameracaptureui.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
ms.assetid: CC0D6E9B-128D-488B-912F-318F5EE2B8D3
3-
description: This article describes how to use the [**CameraCaptureUI**](/uwp/api/windows.media.capture.cameracaptureui) class to capture photos or videos by using the camera UI built into Windows.
4-
title: Capture photos and video with the Windows built-in camera UI
3+
description: This article describes how to use the [**CameraCaptureUI**](/uwp/api/windows.media.capture.cameracaptureui) class to capture photos or videos from a UWP app by using the camera UI built into Windows.
4+
title: Capture photos and video in a UWP app with the Windows built-in camera UI
55
ms.date: 02/08/2017
66
ms.topic: article
77
keywords: windows 10, uwp
@@ -11,10 +11,13 @@ dev_langs:
1111
- cppwinrt
1212
---
1313

14-
# Capture photos and video with the Windows built-in camera UI
14+
# Capture photos and video in a UWP app with the Windows built-in camera UI
1515

1616
This article describes how to use the [**CameraCaptureUI**](/uwp/api/windows.media.capture.cameracaptureui) class to capture photos or videos by using the camera UI built into Windows. This feature is easy to use. It allows your app to get a user-captured photo or video with just a few lines of code.
1717

18+
> [!NOTE]
19+
> The **CameraCaptureUI** class in the [Windows.Media.Capture](/uwp/api/windows.media.capture) namespace is only supported for UWP apps. For desktop apps using WinUI 3, use the new version of this feature in the [Microsoft.Windows.Media.Capture](/windows/windows-app-sdk/api/winrt/microsoft.windows.media.capture) namespace. For more information, see [Capture photos and video in a desktop app with the Windows built-in camera UI](/windows/apps/develop/camera/camera/cameracaptureui.md).
20+
1821
If you want to provide your own camera UI, or if your scenario requires more robust, low-level control of the capture operation, then you should use the [**MediaCapture**](/uwp/api/Windows.Media.Capture.MediaCapture) class, and implement your own capture experience. For more information, see [Basic photo, video, and audio capture with MediaCapture](basic-photo-video-and-audio-capture-with-MediaCapture.md).
1922

2023
> [!NOTE]

0 commit comments

Comments
 (0)