简体   繁体   English

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

[英]How to launch camera app from my windows 10 app programmatically?

I am developing a windows 10 app.我正在开发一个 Windows 10 应用程序。 Please tell me a way to open Camera app from my windows store app.请告诉我一种从我的 Windows 商店应用程序中打开相机应用程序的方法。 I know we can use LaunchUriAsync function to open different app which has a registered Uri in registry.我知道我们可以使用 LaunchUriAsync 函数打开在注册表中注册了 Uri 的不同应用程序。 But the problem is I don't know what is the registered URI for Microsoft windows default camera app.但问题是我不知道 Microsoft Windows 默认相机应用程序的注册 URI 是什么。 If anyone knows the camera URI please share with me.如果有人知道相机 URI,请与我分享。 Or please tell me a way to open windows store app which has no registered URI.或者请告诉我一种打开没有注册 URI 的 Windows 商店应用程序的方法。

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.由于各种原因,打开相机应用程序可能会失败,如果用户的 PC 没有可用的相机(即没有网络摄像头等),相机应用程序本身可能会抛出错误消息,所以我强烈建议要这样做这个。 That said...那就是说...

On Windows 10, at least, the default camera app installs with a protocol URI of microsoft.windows.camera: .至少在 Windows 10 上,默认的相机应用程序使用microsoft.windows.camera:的协议 URI 安装。 (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! (您可以在Control Panel\Programs\Default Programs\Set Associations下找到已安装的协议)编​​辑:注意,事实证明该协议未在 Windows 8.1 上注册,因此请记住这一点!

You can use the LaunchUriAsync API to call that URI, and that should open the Camera app:您可以使用LaunchUriAsync API 来调用该 URI,这应该会打开相机应用程序:

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.如果您需要该功能,我建议您使用相机 API 并构建您自己的相机控件,因为您可能可以测试用户是否甚至可以打开相机,如果运气好的话。 See the Camera Sample we maintain on GitHub if you want an example of that.如果您想要一个示例,请参阅我们在 GitHub 上维护的相机示例

to use the standard camera on back of device:使用设备背面的标准相机:

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

but then you catch some event to control the camera...但是然后你捕捉到一些事件来控制相机......

Not sure exactly but something changed when moving from .net framework to .net core.不确定,但从 .net 框架迁移到 .net 核心时发生了一些变化。 This Worked for me这对我有用

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

Process.Start(ps);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Windows Phone 8.1:如何从我的应用程序启动已安装的应用程序 - Windows Phone 8.1 : how to Launch an Installed app From My app 有没有办法从Windows Phone 8.1应用程序启动手机摄像头应用程序 - Is there a way to launch phone camera app from Windows Phone 8.1 app 如何在 android 中从 Unity 启动相机应用程序? - How to launch Camera app from Unity in android? 如何以编程方式重新启动Windows 10 IoT应用程序 - How to relaunch a Windows 10 IoT app programmatically 从包列表 (FindPackage) 启动 Windows 10 UWP 应用 - Windows 10 UWP App Launch from Package List (FindPackage) 从我的UWP应用启动默认的Microsoft Windows Weather应用 - Launch the default microsoft windows weather app from my UWP App 如何在Windows 10 IoT上启动/切换前台应用程序 - How can I launch/switch foreground app on Windows 10 IoT 从桌面应用程序运行Windows 10的Camera App - Run Camera App of Windows 10 from Desktop Application 如何从Winform启动Windows Universal App - How to launch a Windows Universal App from winform Windows Phone 8.1运行时:如何从我自己的应用程序中启动相册应用程序? - Windows Phone 8.1 runtime: How to launch the photo gallery app from my own app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM