如何以编程方式从我的Windows 10应用程序启动相机应用?

发布于 2025-01-20 06:37:38 字数 227 浏览 1 评论 0原文

我正在开发一个 Windows 10 应用程序。请告诉我一种从 Windows 应用商店应用程序中打开相机应用程序的方法。 我知道我们可以使用 LaunchUriAsync 函数来打开在注册表中注册了 Uri 的不同应用程序。但问题是我不知道 Microsoft Windows 默认相机应用程序的注册 URI 是什么。如果有人知道相机 URI,请与我分享。或者请告诉我一种打开没有注册 URI 的 Windows 应用商店应用程序的方法。

I am developing a windows 10 app. Please tell me a way to open Camera app from my windows store app.
I know we can use LaunchUriAsync function to open different app which has a registered Uri in registry. But the problem is I don't know what is the registered URI for Microsoft windows default camera app. If anyone knows the camera URI please share with me. Or please tell me a way to open windows store app which has no registered URI.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一口甜 2025-01-27 06:37:38

打开相机应用程序可能会因各种原因而失败,如果用户的电脑没有可用的相机(即没有网络摄像头等),相机应用程序本身可能会抛出一条错误消息,所以我强烈建议这样做。也就是说......

至少在 Windows 10 上,默认相机应用程序使用 microsoft.windows.camera: 协议 URI 安装。 (您可以在控制面板\程序\默认程序\设置关联下找到已安装的协议)编辑:注意,事实证明该协议未在 Windows 8.1 上注册,因此请记住这一点也!

您可以使用LaunchUriAsync API 来调用该 URI,并且应该打开相机应用程序:

await Launcher.LaunchUriAsync(new Uri("microsoft.windows.camera:"));

正如我之前所说,这可能会因多种原因而失败,所以我不推荐这样做。如果您需要该功能,我建议您使用相机 API 并构建自己的相机控件,因为如果运气好的话,您甚至可以测试用户是否有要打开的相机。如果需要,请参阅我们在 GitHub 上维护的相机示例一个例子。

Opening the camera app can fail for various reasons, and the camera app itself may just throw out an error message if the user's PC doesn't have a camera available (ie, no webcam, etc), so I'd strongly recommend NOT doing this. That said...

On Windows 10, at least, the default camera app installs with a protocol URI of microsoft.windows.camera:. (You can find installed protocols under Control Panel\Programs\Default Programs\Set Associations) Edit: Note, turns out that this protocol isn't registered on windows 8.1, so keep that in mind too!

You can use the LaunchUriAsync API to call that URI, and that should open the Camera app:

await Launcher.LaunchUriAsync(new Uri("microsoft.windows.camera:"));

As I said before though, this could fail for a bunch of reasons, so I wouldn't recommend this. I'd recommend using the Camera API and building your own camera controls if you need that functionality, since you can probably test if the user even has a camera to open, with a bit of luck. See the Camera Sample we maintain on GitHub if you want an example of that.

沧桑㈠ 2025-01-27 06:37:38

使用设备背面的标准摄像头:

PhotoCameracamera = new Microsoft.Devices.PhotoCamera(CameraType.Primary);

但然后你捕捉到一些事件来控制相机......

to use the standard camera on back of device:

PhotoCamera camera = new Microsoft.Devices.PhotoCamera(CameraType.Primary);

but then you catch some event to control the camera...

哎呦我呸! 2025-01-27 06:37:38

不确定,但从 .net 框架迁移到 .net core 时发生了一些变化。这对我有用

var ps = new ProcessStartInfo("microsoft.windows.camera:")
            {
                UseShellExecute = true,
                Verb = "open"
            };

Process.Start(ps);

Not sure exactly but something changed when moving from .net framework to .net core. This Worked for me

var ps = new ProcessStartInfo("microsoft.windows.camera:")
            {
                UseShellExecute = true,
                Verb = "open"
            };

Process.Start(ps);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文