public void Direction_PROPERTY_READ_ONLY() { CameraFacingDirection direction = TestCamera.Direction; Assert.IsNotNull(direction, "Camera direction should not be null."); Assert.IsInstanceOf <CameraFacingDirection>(direction, "The object should be of type CameraFacingDirection."); }
public PhotoCamera(CameraFacingDirection cameraFacingDirection, bool isEnabled, string name, Context context) { Guard.ArgumentNotNull(() => context); this.CameraFacingDirection = cameraFacingDirection; this.IsEnabled = isEnabled; this.Name = name; this.context = context; }
internal static Integer ToLensFacingInteger(CameraFacingDirection cameraFacingDirection) { if (cameraFacingDirection == CameraFacingDirection.Rear) { return(LENS_FACING_BACK); } return(LENS_FACING_FRONT); }
/// <summary> /// Converts <paramref name="self"/> to a <c>Feature</c>. /// </summary> /// <param name="self">The <see cref="CameraFacingDirection"/> being extended.</param> /// <returns>The <c>Feature</c> representation of the camera facing direction.</returns> public static Feature ToFeature(this CameraFacingDirection self) { switch (self) { case CameraFacingDirection.World: return(Feature.WorldFacingCamera); case CameraFacingDirection.User: return(Feature.UserFacingCamera); default: return(Feature.None); } }
public static CameraType ToCameraType(this CameraFacingDirection cameraFacingDirection) { switch (cameraFacingDirection) { case CameraFacingDirection.Front: return(CameraType.FrontFacing); case CameraFacingDirection.Rear: return(CameraType.Primary); default: throw new InvalidOperationException(string.Format("Could not find mapping for CameraFacingDirection {0}.", cameraFacingDirection)); } }
private static UIImagePickerControllerCameraDevice GetUICameraDevice(CameraFacingDirection cameraFacingDirection) { switch (cameraFacingDirection) { case CameraFacingDirection.Front: return(UIImagePickerControllerCameraDevice.Front); case CameraFacingDirection.Rear: return(UIImagePickerControllerCameraDevice.Rear); default: throw new NotSupportedException(); } }
public CameraCaptureUI(CameraFacingDirection cameraFacingDirection) { this.StopFlag = false; this.InitializeComponent(); this.cameraFacingDirection = cameraFacingDirection == CameraFacingDirection.Undefined ? CameraFacingDirection.Front : cameraFacingDirection; this.Unloaded += this.OnUnloaded; var pageName = typeof(CameraCaptureUIPage).Name; this.rootVisual = (PhoneApplicationFrame)Application.Current.RootVisual; this.rootVisual.Navigated += this.OriginalFrameNavigated; this.rootVisual.Navigate(new Uri(string.Format("/CrossPlatformLibrary.Camera.Platform;component/{0}.xaml", pageName), UriKind.Relative)); this.StartPumpingFrames(); // TODO GATH: can be later, when TakePicture method is called }
public ViewFinder(CameraFacingDirection cameraFacingDirection) { this.InitializeComponent(); this.stopFlag = false; this.SensorLocation = cameraFacingDirection == CameraFacingDirection.Front ? CameraSensorLocation.Front : CameraSensorLocation.Back; this.EnableShutterKey = true; this.LayoutUpdated += this.OnLayoutUpdated; if (DesignerProperties.IsInDesignTool == false) { this.rootVisual = (PhoneApplicationFrame)Application.Current.RootVisual; this.rootVisual.OrientationChanged += this.OnOrientationChanged; this.Tap += this.ViewFinderTap; this.Loaded += this.OnViewFinderLoaded; this.Unloaded += this.OnViewFinderUnloaded; // Navigate to ViewFinderPage var pageName = typeof(ViewFinderPage).Name; this.rootVisual = (PhoneApplicationFrame)Application.Current.RootVisual; this.rootVisual.Navigated += this.OnNavigated; this.rootVisual.Navigate(new Uri(string.Format("/CrossPlatformLibrary.Camera.Platform;component/{0}.xaml", pageName), UriKind.Relative)); } }
internal static extern CameraError GetFacingDirection(IntPtr handle, out CameraFacingDirection direction);
// Opens a CameraDevice. The result is listened to by 'cameraStateListener'. private void OpenCamera() { var activity = this.Activity; if (activity == null || activity.IsFinishing) { return; } this.tracer.Debug("OpenCamera"); this.tracer.Debug("OpenCamera: this.facing={0}", this.facing.ToString()); var cameraManager = (CameraManager)activity.GetSystemService(Context.CameraService); try { if (!this.mCameraOpenCloseLock.TryAcquire(2500, TimeUnit.Milliseconds)) { const string ErrorMessage = "Time out waiting to lock camera opening."; this.tracer.Error(ErrorMessage); throw new RuntimeException(ErrorMessage); } string idForOpen = null; string[] camerasIds = cameraManager.GetCameraIdList(); foreach (string id in camerasIds) { CameraCharacteristics cameraCharacteristics = cameraManager.GetCameraCharacteristics(id); var cameraLensFacing = (Integer)cameraCharacteristics.Get(CameraCharacteristics.LensFacing); CameraFacingDirection cameraFacingDirection = ToCameraFacingDirection(cameraLensFacing); CameraFacingDirection configuredFacingDirection = ToCameraFacingDirection(this.facing); this.tracer.Debug("OpenCamera: cameraFacingDirection={0}, configuredFacingDirection={1}", cameraFacingDirection, configuredFacingDirection); if (cameraFacingDirection == configuredFacingDirection) { idForOpen = id; break; } } var cameraId = idForOpen ?? camerasIds[0]; this.tracer.Debug("OpenCamera: idForOpen={0}", idForOpen); this.tracer.Debug("OpenCamera: idForOpen={0}", idForOpen); this.tracer.Debug("OpenCamera: cameraId={0}", cameraId); // To get a list of available sizes of camera preview, we retrieve an instance of // StreamConfigurationMap from CameraCharacteristics CameraCharacteristics characteristics = cameraManager.GetCameraCharacteristics(cameraId); StreamConfigurationMap map = (StreamConfigurationMap)characteristics.Get(CameraCharacteristics.ScalerStreamConfigurationMap); this.previewSize = map.GetOutputSizes(Class.FromType(typeof(SurfaceTexture)))[0]; // We assume that the top-most element is the one with the best resolution Orientation orientation = this.Resources.Configuration.Orientation; if (orientation == Orientation.Landscape) { this.autoFitTextureView.SetAspectRatio(this.previewSize.Width, this.previewSize.Height); } else { this.autoFitTextureView.SetAspectRatio(this.previewSize.Height, this.previewSize.Width); } ////this.ConfigureTransform(this.autoFitTextureView.Width, this.autoFitTextureView.Width); // We are opening the camera with a listener. When it is ready, OnOpened of cameraStateListener is called. cameraManager.OpenCamera(cameraId, this.cameraStateListener, null); } catch (CameraAccessException caex) { this.tracer.Exception(caex, "Cannot access the camera."); Toast.MakeText(activity, "Cannot access the camera.", ToastLength.Short).Show(); this.Activity.Finish(); } catch (NullPointerException npex) { this.tracer.Exception(npex, "This device doesn't support Camera2 API."); var dialog = new ErrorDialog(); dialog.Show(this.FragmentManager, "dialog"); } catch (InterruptedException e) { const string ErrorMessage = "Interrupted while trying to lock camera opening."; this.tracer.Exception(e, ErrorMessage); throw new RuntimeException(ErrorMessage); } catch (Exception ex) { this.tracer.Exception(ex); throw; } }
/// <summary> /// Request that the provider use the camera with the given facing direction, if possible /// </summary> /// <param name="facingDirection">The requested camera facing direction</param> public static void RequestCameraFacingDirection(this IUsesCameraTexture obj, CameraFacingDirection facingDirection) { obj.provider.RequestCameraFacingDirection(facingDirection); }
private static MediaPickerController SetupController(MediaPickerDelegate mpDelegate, UIImagePickerControllerSourceType sourceType, string mediaType, CameraFacingDirection cameraFacingDirection, StoreMediaOptions options) { var picker = new MediaPickerController(mpDelegate); picker.MediaTypes = new[] { mediaType }; picker.SourceType = sourceType; if (sourceType == UIImagePickerControllerSourceType.Camera) { picker.CameraDevice = GetUICameraDevice(cameraFacingDirection); picker.AllowsEditing = options.AllowCropping; if (options.OverlayViewProvider != null) { var overlay = options.OverlayViewProvider; if (overlay is UIView) { picker.CameraOverlayView = overlay as UIView; } } if (mediaType == Constants.TypeImage) { picker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Photo; } else if (mediaType == Constants.TypeMovie) { StoreVideoOptions voptions = (StoreVideoOptions)options; picker.CameraCaptureMode = UIImagePickerControllerCameraCaptureMode.Video; picker.VideoQuality = GetQuailty(voptions.Quality); picker.VideoMaximumDuration = voptions.DesiredLength.TotalSeconds; } } return(picker); }
public PhotoCamera(CameraFacingDirection cameraFacingDirection, bool isEnabled, string name) { this.CameraFacingDirection = cameraFacingDirection; this.IsEnabled = isEnabled; this.Name = name; }
private Task <MediaFile> GetMediaAsync(UIImagePickerControllerSourceType sourceType, string mediaType, CameraFacingDirection cameraFacingDirection, StoreMediaOptions options = null) { var window = UIApplication.SharedApplication.KeyWindow; if (window == null) { throw new InvalidOperationException("There's no current active window"); } var viewController = window.RootViewController; if (viewController == null) { window = UIApplication.SharedApplication.Windows.OrderByDescending(w => w.WindowLevel).FirstOrDefault(w => w.RootViewController != null); if (window == null) { throw new InvalidOperationException("Could not find current view controller"); } else { viewController = window.RootViewController; } } while (viewController.PresentedViewController != null) { viewController = viewController.PresentedViewController; } MediaPickerDelegate ndelegate = new MediaPickerDelegate(viewController, sourceType, options); var od = Interlocked.CompareExchange(ref this.pickerDelegate, ndelegate, null); if (od != null) { throw new InvalidOperationException("Only one operation can be active at at time"); } var picker = SetupController(ndelegate, sourceType, mediaType, cameraFacingDirection, options); if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad && sourceType == UIImagePickerControllerSourceType.PhotoLibrary) { ndelegate.Popover = new UIPopoverController(picker); ndelegate.Popover.Delegate = new MediaPickerPopoverDelegate(ndelegate, picker); ndelegate.DisplayPopover(); } else { viewController.PresentViewController(picker, true, null); } return(ndelegate.Task.ContinueWith( t => { if (this.popover != null) { this.popover.Dispose(); this.popover = null; } Interlocked.Exchange(ref this.pickerDelegate, null); return t; }).Unwrap()); }
public VideoCamera(CameraFacingDirection cameraFacingDirection, bool isEnabled, string name) : base(cameraFacingDirection, isEnabled, name) { }
void IProvidesCameraTexture.RequestCameraFacingDirection(CameraFacingDirection facingDirection) { // Not implemented - video feed in simulation is either always user-facing or always world-facing }