Neena
Neena

Reputation: 133

Open Camera app installed from a UWP app and capture image

Instead of creating a Windows built-in camera UI (CameraCaptureUI) or using a custom MediaCapture control and capture picture I want to open any Camera App downloaded in the device to capture an image and get the result.

I have used

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

var uri = new Uri(uriToLaunch);

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

But this just opens the camera app, I need to get the result file back to the app and save it. Is there a way to do this?

Upvotes: 1

Views: 835

Answers (1)

Romasz
Romasz

Reputation: 29792

The method you are using:

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

just opens the default camera, nothing more, the result is a boolean with information if the application has been opened successfully, nothing more.

With CameraCaptureUI you don't need to create camera - this seems to be designed for the task like you have described. With lines:

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

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

you just launch the camera app and your app waits for the photo, which you can process further/save.

If you don't want to use it or implement own camera capture, you can think of sharing a picture taken by other app. This is described well at app-to-app communication at MSDN. In this case user will have to click Share button and choose your app as a target. That will invoke OnShareTargetActivated event where you can process the received content.

Upvotes: 1

Related Questions