Automatically taking photos -- something similar to UWP's MediaCapture functionality

DC Dweller 1 Reputation point
2022-04-02T22:15:40.027+00:00

A wrote a robotics app using UWP a few years ago, which automatically takes photos. I want to convert it to an Android (and possibly iOS) app with Xamarin, but I noticed that Xamarin's MediaPicker is a far cry from UWP's MediaCapture object. With MediaCapture I could have my app take several pictures completely on its own, without the user having to click on any buttons, with this code:

MediaCapture mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync(mediaSettings);
Low​Lag​Photo​Capture photoCapture = await mediaCapture.PrepareLowLagPhotoCaptureAsync(imageProperties);
CapturedPhoto photo = await photoCapture.CaptureAsync();
CapturedFrame frame = photo.Frame;
SoftwareBitmap SWBitmap = frame.SoftwareBitmap;

Is there a way to do the same in Xamarin?

Thanks a lot.

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,312 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rob Caplan - MSFT 5,427 Reputation points Microsoft Employee
    2022-04-03T17:43:14.46+00:00

    Xamarin provides access to the full platform API for whichever platform you run on. You can use Android's Camera2 API to automatically take photos from a Xamarin app on Android just as you can use UWP's MediaCapture to do so from a Xamarin app on Windows.

    API doc: Android.Hardware.Camera2
    Sample: Xamarin.Android - Camera2 Basic Sample. This isn't a Forms sample and is probably a bit out of date, but it should give some basic guidance on how the Camera2 API works.

    0 comments No comments