Skip to content

Commit 9498d3d

Browse files
Merge pull request #5304 from MicrosoftDocs/main
main to live merge for PowerToys public repo PRs in 0.90 release for alvinashcraft
2 parents e0bc1bf + 3a1c586 commit 9498d3d

File tree

6 files changed

+222
-7
lines changed

6 files changed

+222
-7
lines changed

hub/apps/develop/camera/camera.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This section provides guidance for creating WinUI 3 apps that use the camera or
1515

1616
| Topic | Description |
1717
|---------------------------|-----------------------------|
18+
| [Capture photos and video in a desktop app with the Windows built-in camera UI](cameracaptureui.md) | 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. |
1819
| [Show the camera preview in a WinUI 3 app](camera-quickstart-winui3.md) | Shows how to quickly display the camera preview stream within a XAML page in a WinUI 3 app. |
1920
| [Basic photo, video, and audio capture with MediaCapture](basic-photo-capture.md) | Shows the simplest way to capture photos and video using the [**MediaCapture**](/uwp/api/Windows.Media.Capture.MediaCapture) class. The **MediaCapture** class exposes a robust set of APIs that provide low-level control over the capture pipeline and enable advanced capture scenarios, but this article is intended to help you add basic media capture to your app quickly and easily. |
2021

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
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.md).
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+
## Use the CameraCaptureUI class to capture photos
21+
22+
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 trim the video after it's captured.
23+
24+
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.
25+
26+
The following example demonstrates launching the **CameraCaptureUI** for photo capture, specifying the image format as PNG and disabling cropping. In this example the captured photo is set as the source for an [Image](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.image) control.
27+
28+
### [C#](#tab/csharp)
29+
30+
```csharp
31+
var cameraCaptureUI = new CameraCaptureUI(this.AppWindow.Id);
32+
cameraCaptureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Png;
33+
cameraCaptureUI.PhotoSettings.AllowCropping = false;
34+
35+
// Capture a photo asynchronously
36+
StorageFile photo = await cameraCaptureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);
37+
38+
if (photo != null)
39+
{
40+
// Photo capture was successful
41+
42+
// Show the captured photo in a XAML Image control
43+
using (IRandomAccessStream fileStream = await photo.OpenAsync(Windows.Storage.FileAccessMode.Read))
44+
{
45+
// Set the image source to the selected bitmap
46+
BitmapImage bitmapImage = new BitmapImage();
47+
await bitmapImage.SetSourceAsync(fileStream);
48+
iCapturedImage.Source = bitmapImage;
49+
}
50+
} else
51+
{
52+
// Photo capture failed or was cancelled
53+
}
54+
55+
```
56+
57+
### [C++/WinRT](#tab/cpp)
58+
59+
```cpp
60+
// Get the WindowId for the window
61+
Microsoft::UI::WindowId windowId = this->AppWindow().Id();
62+
63+
// Initialize CameraCaptureUI with a window handle
64+
winrt::Microsoft::Windows::Media::Capture::CameraCaptureUI cameraUI(windowId);
65+
66+
// Configure Photo Settings
67+
cameraUI.PhotoSettings().Format(CameraCaptureUIPhotoFormat::Png);
68+
cameraUI.PhotoSettings().AllowCropping(false);
69+
70+
// Capture a photo asynchronously
71+
auto photo = co_await cameraUI.CaptureFileAsync(CameraCaptureUIMode::Photo);
72+
73+
74+
if (photo != nullptr)
75+
{
76+
// Photo capture was successful
77+
78+
// Show the captured photo in a XAML Image control
79+
IRandomAccessStream fileStream = co_await photo.OpenAsync(Windows::Storage::FileAccessMode::Read);
80+
BitmapImage bitmapImage = BitmapImage();
81+
co_await bitmapImage.SetSourceAsync(fileStream);
82+
iCapturedImage().Source(bitmapImage);
83+
84+
}
85+
else
86+
{
87+
// Photo capture failed or was cancelled
88+
}
89+
```
90+
91+
---
92+
93+
## Use the CameraCaptureUI class to capture videos
94+
95+
The following example demonstrates launching the **CameraCaptureUI** for video capture, specifying the maximum video as standard definition and disabling trimming. In this example the captured photo is set as the source for an [MediaPlayerElement](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.mediaplayerelement) control.
96+
97+
### [C#](#tab/csharp)
98+
99+
```csharp
100+
var cameraCaptureUI = new CameraCaptureUI(this.AppWindow.Id);
101+
cameraCaptureUI.VideoSettings.MaxResolution = CameraCaptureUIMaxVideoResolution.StandardDefinition;
102+
cameraCaptureUI.VideoSettings.AllowTrimming = true;
103+
StorageFile videoFile = await cameraCaptureUI.CaptureFileAsync(CameraCaptureUIMode.Video);
104+
105+
if (videoFile != null)
106+
{
107+
// Video capture was successful
108+
109+
// Show the captured video in a MediaPlayerElement control
110+
mediaPlayerElement.Source = MediaSource.CreateFromStorageFile(videoFile);
111+
mediaPlayerElement.MediaPlayer.Play();
112+
}
113+
else
114+
{
115+
// Video capture failed or was cancelled
116+
}
117+
```
118+
119+
### [C++/WinRT](#tab/cpp)
120+
121+
```cpp
122+
Microsoft::UI::WindowId windowId = this->AppWindow().Id();
123+
124+
winrt::Microsoft::Windows::Media::Capture::CameraCaptureUI cameraUI(windowId);
125+
126+
cameraUI.VideoSettings().MaxResolution(CameraCaptureUIMaxVideoResolution::StandardDefinition);
127+
cameraUI.VideoSettings().AllowTrimming(true);
128+
StorageFile videoFile = co_await cameraUI.CaptureFileAsync(CameraCaptureUIMode::Video);
129+
130+
if (videoFile != nullptr)
131+
{
132+
// Video capture was successful
133+
134+
// Show the captured video in a MediaPlayerElement control
135+
auto source = winrt::Windows::Media::Core::MediaSource::CreateFromStorageFile(videoFile);
136+
mediaPlayerElement().Source(MediaSource::CreateFromStorageFile(videoFile));
137+
138+
}
139+
else
140+
{
141+
// Photo capture failed or was cancelled
142+
}
143+
```
144+
145+
---
146+
147+
## Move and rename captured media files
148+
149+
The **CameraCaptureUI** creates randomized names for captured media files, so you may want to rename and move captured files to keep them organized. The following example moves and renames a captured file.
150+
151+
152+
### [C#](#tab/csharp)
153+
154+
```csharp
155+
StorageFile photo = await cameraCaptureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);
156+
157+
if (photo != null)
158+
{
159+
// Move and rename captured photo
160+
StorageFolder destinationFolder =
161+
await ApplicationData.Current.LocalFolder.CreateFolderAsync("ProfilePhotoFolder",
162+
CreationCollisionOption.OpenIfExists);
163+
164+
await photo.CopyAsync(destinationFolder, "ProfilePhoto.jpg", NameCollisionOption.ReplaceExisting);
165+
await photo.DeleteAsync();
166+
}
167+
```
168+
169+
### [C++/WinRT](#tab/cpp)
170+
171+
```cpp
172+
auto photo = co_await cameraUI.CaptureFileAsync(CameraCaptureUIMode::Photo);
173+
174+
175+
if (photo != nullptr)
176+
{
177+
// Move and rename captured photo
178+
StorageFolder destinationFolder = co_await ApplicationData::Current().LocalFolder()
179+
.CreateFolderAsync(L"ProfilePhotoFolder", CreationCollisionOption::OpenIfExists);
180+
181+
co_await photo.CopyAsync(destinationFolder, L"ProfilePhoto.jpg", NameCollisionOption::ReplaceExisting);
182+
co_await photo.DeleteAsync();
183+
}
184+
```
185+
186+
---

hub/apps/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ items:
3838
- name: Camera
3939
href: develop\camera\camera.md
4040
items:
41+
- name: Capture photos and video with Windows built-in camera UI
42+
href: develop\camera\cameracaptureui.md
4143
- name: Show the camera preview in a WinUI 3 app
4244
href: develop\camera\camera-quickstart-winui3.md
4345
- name: Basic photo, video, and audio capture with MediaCapture
9.04 KB
Loading

hub/powertoys/peek.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
22
title: PowerToys Peek utility for Windows
33
description: A system-wide utility for Windows to quickly preview file content.
4-
ms.date: 11/19/2024
4+
ms.date: 01/28/2025
55
ms.topic: concept-article
66
no-loc: [PowerToys, Windows, Peek, Win]
77
# Customer intent: Learn how to configure and use the Peek utility in PowerToys.
88
---
99

1010
# Peek utility
1111

12-
A system-wide utility for Windows to preview file content without the need to open multiple applications or interrupt your workflow. It offers a seamless and quick file preview experience for various file types, including images, Office documents, web pages, Markdown files, text files, and developer files.
12+
A system-wide utility for Windows to preview file content without the need to open multiple applications or interrupt your workflow. It offers a seamless and quick file preview experience for various file types, including images, Office documents, videos, web pages, Markdown files, text files, and developer files. Peek also lets you see summary information about folders.
1313

1414
![Screenshot of PowerToys Peek utility](../images/powertoys-peek.png)
1515

@@ -21,12 +21,34 @@ Using <kbd>Left</kbd> and <kbd>Right</kbd> or <kbd>Up</kbd> and <kbd>Down</kbd>,
2121

2222
## Pin preview window position and size
2323

24-
The Peek window adjusts its size based on the dimensions of the images being previewed. However, if you prefer to keep the window's size and position, you can use the pinning feature. By selecting the pinning button, the window will preserve the current size and position. Selecting the pinning button again will unpin the window. When unpinned, the Peek window will return to the default position and size when previewing the next file.
24+
The Peek window adjusts its size based on the dimensions of the images being previewed. However, if you prefer to keep the window's size and position, you can use the pinning feature.
25+
26+
By selecting the pinning button, the window will preserve the current size and position. Selecting the pinning button again will unpin the window. When unpinned, the Peek window will return to the default position and size when previewing the next file.
2527

2628
## Open file with the default program
2729

2830
Select **Open with** or <kbd>Enter</kbd> to open the current file with the default program.
2931

32+
## See extra information about the current file
33+
34+
Hover over the preview to see extra information about the file, including its size, type, and when it was last modified.
35+
36+
## Delete files
37+
38+
Press the <kbd>Delete</kbd> key to move the current file to the Recycle Bin.
39+
40+
By default, a confirmation dialog will appear before deletions. To skip future confirmations, either:
41+
42+
- Check the "Don't show this warning again" checkbox in the dialog.
43+
- Uncheck the "Ask for confirmation before deleting files" option in Peek's settings page.
44+
45+
![A screenshot of Peek's file deletion confirmation dialog](../images/pt-peek-delete-confirmation.png)
46+
47+
After deleting the file, Peek will automatically preview the next file. If there are no more files to preview, a message will be displayed.
48+
49+
> [!TIP]
50+
> Only files may be deleted. Folders may not be deleted, even if they are empty.
51+
3052
## Settings
3153

3254
From the settings page, the following options can be configured:
@@ -35,6 +57,7 @@ From the settings page, the following options can be configured:
3557
| :--- | :--- |
3658
| Activation shortcut | The customizable keyboard command to open Peek for the selected file(s). |
3759
| Always run not elevated, even when PowerToys is elevated | Tries to run Peek without elevated permissions, to fix access to network shares. |
38-
| Automatically close the Peek window after it loses focus | |
60+
| Automatically close the Peek window after it loses focus | |
61+
| Ask for confirmation before deleting files | When enabled, Peek shows a confirmation dialog before deleting files. |
3962

4063
[!INCLUDE [install-powertoys.md](../includes/install-powertoys.md)]

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/cameracaptureui).
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)