locked
How does the camera swap Rear / Front with the Bindableproperty? (ViewRenderer Example) RRS feed

  • Question

  • User206406 posted

    Hello together,

    I do not understand how the example https://developer.xamarin.com/guides/xamarin-forms/custom-renderer/view/ is changing the Camera from Front to Rear. There is a Bindableproperty, which has the default value CameraOptions Enum (Rear or Front). The Mainpage sets this BindableProperty. But where is the Point to consume this Option? In the Android.CameraPreview.cs there is no CameraOption or openCamera(id),... Maybe it is very easy to understand, but I have searched for hours now.

    I would be very grateful if you could help me!

    Greeting Patrick

    Wednesday, April 13, 2016 7:43 PM

Answers

  • User206406 posted

    now I have found it :-) I have overlooked it.

    if (e.NewElement != null) { Control.Preview = Camera.Open ((int)e.NewElement.Camera);

                // Subscribe
                cameraPreview.Click += OnCameraPreviewClicked;
    

    }

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, April 15, 2016 2:55 PM

All replies

  • User132529 posted

    That's just a trick, in Android renderer it call Camera.open(int id) function to open a camera. Generally, we pass Camera.CameraInfo to set front or back camera, and the value is the same with CameraOptions in PCL codes.

    Wednesday, April 13, 2016 11:03 PM
  • User206406 posted

    @JesseJiang.8365 said: That's just a trick, in Android renderer it call Camera.open(int id) function to open a camera. Generally, we pass Camera.CameraInfo to set front or back camera, and the value is the same with CameraOptions in PCL codes.

    Thanks for your quick reply :smile: . Could you show me this in Code (https://github.com/xamarin/xamarin-forms-samples/tree/master/CustomRenderers/View)? In wich class is the method Camera.open(int id) or the Camera.CameraInfo? It do not quite become clear to me.

    (The reason because i ask, I want to change the front/back camera with a button in a shared Project, and other functions like capture)

    Thursday, April 14, 2016 11:57 AM
  • User206406 posted

    now I have found it :-) I have overlooked it.

    if (e.NewElement != null) { Control.Preview = Camera.Open ((int)e.NewElement.Camera);

                // Subscribe
                cameraPreview.Click += OnCameraPreviewClicked;
    

    }

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, April 15, 2016 2:55 PM