从UWP应用程序安装的Open Camera应用程序并捕获图像

时间:2017-02-08 02:57:16

标签: camera uwp

我没有创建Windows内置相机UI(CameraCaptureUI)或使用自定义MediaCapture控件和捕获图片,而是打开设备中下载的任何相机应用程序以捕获图像并获得结果。

我用过

string uriToLaunch = "microsoft.windows.camera:";

var uri = new Uri(uriToLaunch);

var success = await Windows.System.Launcher.LaunchUriAsync(uri);

但这只是打开相机应用程序,我需要将结果文件返回到应用程序并保存。 有没有办法做到这一点?

1 个答案:

答案 0 :(得分:0)

您正在使用的方法:

var success = await Windows.System.Launcher.LaunchUriAsync(uri);

只需打开默认摄像头,仅此而已,结果是布尔,如果应用程序已成功打开,则显示信息,仅此而已。

使用CameraCaptureUI您不需要创建相机 - 这似乎是为您所描述的任务而设计的。用行:

var captureUI = new CameraCaptureUI();
captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
captureUI.PhotoSettings.CroppedSizeInPixels = new Size(200, 200); 

var photo = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

您只需启动相机应用程序,您的应用就会等待照片,您可以进一步处理/保存。

如果您不想使用它或implement own camera capture,您可以考虑共享其他应用拍摄的照片。这是described well at app-to-app communication at MSDN。在这种情况下,用户必须单击 Share 按钮并选择您的应用作为目标。这将调用OnShareTargetActivated事件,您可以在其中处理收到的内容。