Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open front face camera

I am trying to open front facing camera but its opening default back camera.Please Suggest me how to achieve this?

CameraCaptureUI captureUI = new CameraCaptureUI();
captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
StorageFile photo =await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

if (photo == null)
{
    // User cancelled photo capture
    return;
}
like image 806
Robert Avatar asked Jan 31 '26 06:01

Robert


1 Answers

Instead of CameraCaptureUI, you can try to use the MediaCapture class: https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn642092.aspx

You can query for the available cameras by using DeviceInformation class, for example:

  DeviceInformation device = (await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture))
      .FirstOrDefault(d => d.EnclosureLocation != null && d.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front);

and if a device is returned, set it's id in the MediaCaptureInitializationSettings class:

MediaCaptureInitializationSettings settings = new MediaCaptureInitializationSettings();
settings.VideoDeviceId = device.Id;

MediaCapture mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync(settings);
like image 95
Jogy Avatar answered Feb 02 '26 19:02

Jogy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!