Hi - how can i open the front camera using Xamarin Forms?
I've got the following code which seems to default to the rear camera. I'd need to restrict it to the front camera only
var requestPermission = await Permissions.RequestAsync<Permissions.Camera>(); var status = await Xamarin.Essentials.Permissions.CheckStatusAsync<Permissions.Camera>(); if (status != Xamarin.Essentials.PermissionStatus.Granted) { await DisplayAlert("Can't access camera", "Please grant access to Camera to upload a profile picture", "OK"); return; } var photo = await MediaPicker.CapturePhotoAsync(new MediaPickerOptions { Title ="Please take a selfie" });
Answers
It seems that Xamarin.Essentials does not yet reveal any interface for setting up front and rear camera.
For this, you can post a new feature request here: https://github.com/xamarin/Essentials/issues
Thanks for your support for xamarin.
Xamarin forums are migrating to a new home on Microsoft Q&A!
We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
For more information, please refer to this sticky post.
Is there any other way to open the front camera only through Xamarin forms?
For this, you can check the official document Implementing a View of Custom Renderers .
This article demonstrates how to create a custom renderer for a Xamarin.Forms custom control that's used to display a preview video stream from the device's camera.
And you can check the sample here: https://github.com/xamarin/xamarin-forms-samples/tree/master/CustomRenderers/View
Here we can change to the front camera in class
CameraPreview
:We can change the
CameraOptions.Rear
toCameraOptions.Front
.Xamarin forums are migrating to a new home on Microsoft Q&A!
We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
For more information, please refer to this sticky post.