On Aug 30, 2012, at 7:01 PM, technohead <technoh...@gmail.com> wrote:
>  anyone know if it's possible to use the front facing camera?
It should be...

> There doesn't appear to be a way to get the count of cameras,

        
http://androidapi.xamarin.com/?link=P%3aAndroid.Hardware.Camera.NumberOfCameras

> and trying to open call the static method Open when there is only a front 
> facing camera (on the Nexus 7)

Camera.Open() is documented as returning the first back-facing camera:

        
http://androidapi.xamarin.com/index.aspx?link=M%3aAndroid.Hardware.Camera.Open()
> Creates a new Camera object to access the first back-facing camera on the 
> device. If the device does not have a back-facing camera, this returns null.

You need to use Camera.Open(int), where `cameraid` is the ID of the camera to 
open.

If you know you're on the Nexus 7, this should work:

        var camera = Camera.Open(0);

However, if you want to code sanely and want the first front-facing camera...

        static IEnumerable<Tuple<int, Camera.CameraInfo>> GetCameras ()
        {
                int end = Camera.NumberOfCameras;
                for (int i = 0; i < end; ++i) {
                        var info = new Camera.CameraInfo ();
                        Camera.GetCameraInfo (i, info);
                        yield return Tuple.Create (i, info);
                }
        }

        static int? GetFrontFacingCamera ()
        {
                var front = GetCameras ().FirstOrDefault (c => c.Item2.Facing 
== CameraFacing.Front);
                return front != null ? front.Item1 : null;
        }

 - Jon

_______________________________________________
Monodroid mailing list
Monodroid@lists.ximian.com

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to