/// <summary>
        /// Initializes a new photo capture controller, if needed.
        /// </summary>
        /// <param name="captureMode">Photo capture mode.</param>
        /// <param name="parameters">Camera capture parameters.</param>
        /// <returns>Awaitable task.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="parameters"/> is <see langword="null"/>.</exception>
        /// <exception cref="NotImplementedException"><paramref name="captureMode"/> is not supported.</exception>
        public async Task InitializePhotoCaptureAsync(CaptureMode captureMode, CaptureParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            if (parameters.ImageEncoding == null)
            {
                throw new ArgumentNullException("parameters", "Image encoding is not set.");
            }

            Tracing.Trace("PhotoCamera::InitializePhotoCaptureAsync");

            if (this.photoCapture != null && this.CaptureMode == captureMode && parameters.Equals(this.CaptureParameters))
            {
                Tracing.Trace("PhotoCamera: Capture is already initialized with the same parameters.");
                return;
            }

            this.CaptureMode       = captureMode;
            this.CaptureParameters = parameters;

            await this.DestroyPhotoCaptureAsync();

            this.photoCapture = this.CreatePhotoCapture(captureMode);

            await this.TaskEngine.EnqueueTaskAsync(new InitializePhotoCaptureTask(this.CameraController, this.photoCapture, parameters));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="StartPhotoCaptureTask"/> class.
        /// </summary>
        /// <param name="cameraController">Current camera controller.</param>
        /// <param name="photoCapture">Photo capture to stop.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="cameraController"/> is <see langword="null"/>.
        ///     <para>-or-</para>
        /// <paramref name="photoCapture"/> is <see langword="null"/>.
        /// </exception>
        public StartPhotoCaptureTask(CameraController cameraController, IPhotoCapture photoCapture)
            : base(cameraController)
        {
            if (photoCapture == null)
            {
                throw new ArgumentNullException("photoCapture");
            }

            this.photoCapture = photoCapture;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="StartPhotoCaptureTask"/> class.
        /// </summary>
        /// <param name="cameraController">Current camera controller.</param>
        /// <param name="photoCapture">Photo capture to stop.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="cameraController"/> is <see langword="null"/>.
        ///     <para>-or-</para>
        /// <paramref name="photoCapture"/> is <see langword="null"/>.
        /// </exception>
        public StartPhotoCaptureTask(CameraController cameraController, IPhotoCapture photoCapture)
            : base(cameraController)
        {
            if (photoCapture == null)
            {
                throw new ArgumentNullException("photoCapture");
            }

            this.photoCapture = photoCapture;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="InitializePhotoCaptureTask"/> class.
        /// </summary>
        /// <param name="cameraController">Current camera controller.</param>
        /// <param name="photoCapture">Photo capture to initialize.</param>
        /// <param name="captureParameters">Photo capture parameters.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="cameraController"/> is <see langword="null"/>.
        ///     <para>-or-</para>
        /// <paramref name="photoCapture"/> is <see langword="null"/>.
        ///     <para>-or-</para>
        /// <paramref name="captureParameters"/> is <see langword="null"/>.
        /// </exception>
        public InitializePhotoCaptureTask(CameraController cameraController, IPhotoCapture photoCapture, CaptureParameters captureParameters)
            : base(cameraController)
        {
            if (photoCapture == null)
            {
                throw new ArgumentNullException("photoCapture");
            }

            if (captureParameters == null)
            {
                throw new ArgumentNullException("captureParameters");
            }

            this.photoCapture      = photoCapture;
            this.captureParameters = captureParameters;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="InitializePhotoCaptureTask"/> class.
        /// </summary>
        /// <param name="cameraController">Current camera controller.</param>
        /// <param name="photoCapture">Photo capture to initialize.</param>
        /// <param name="captureParameters">Photo capture parameters.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="cameraController"/> is <see langword="null"/>.
        ///     <para>-or-</para>
        /// <paramref name="photoCapture"/> is <see langword="null"/>.
        ///     <para>-or-</para>
        /// <paramref name="captureParameters"/> is <see langword="null"/>.
        /// </exception>
        public InitializePhotoCaptureTask(CameraController cameraController, IPhotoCapture photoCapture, CaptureParameters captureParameters)
            : base(cameraController)
        {
            if (photoCapture == null)
            {
                throw new ArgumentNullException("photoCapture");
            }

            if (captureParameters == null)
            {
                throw new ArgumentNullException("captureParameters");
            }

            this.photoCapture      = photoCapture;
            this.captureParameters = captureParameters;
        }
        /// <summary>
        /// Stops and unloads the current <see cref="photoCapture"/>.
        /// </summary>
        private async Task DestroyPhotoCaptureAsync()
        {
            if (this.photoCapture == null)
            {
                return;
            }

            if (this.captureStarted)
            {
                Tracing.Trace("PhotoCamera: Stopping photo capture.");
                await this.photoCapture.StopAsync();
            }

            Tracing.Trace("PhotoCamera: Unloading photo capture.");
            await this.photoCapture.UnloadAsync();

            this.UnsubscribeFromCaptureEvents(this.photoCapture);
            this.photoCapture = null;
        }
        /// <summary>
        /// Unsubscribes from the <paramref name="capture"/> events.
        /// </summary>
        /// <param name="capture">Photo capture.</param>
        private void UnsubscribeFromCaptureEvents(IPhotoCapture capture)
        {
            Tracing.Trace("PhotoCamera: Unsubscribing from capture events.");

            capture.Started -= this.CaptureOnStarted;
            capture.Stopped -= this.CaptureOnStopped;

            LowLagCapture lowLagCapture = capture as LowLagCapture;

            if (lowLagCapture != null)
            {
                lowLagCapture.PhotoCaptured -= this.LowLagCaptureOnPhotoCaptured;
                return;
            }

            VariablePhotoCapture variableCapture = capture as VariablePhotoCapture;

            if (variableCapture != null)
            {
                variableCapture.PhotoCaptured -= this.VariableCaptureOnPhotoCaptured;
            }
        }
        /// <summary>
        /// Subscribes to the <paramref name="capture"/> events.
        /// </summary>
        /// <param name="capture">Photo capture.</param>
        private void SubscribeToCaptureEvents(IPhotoCapture capture)
        {
            Tracing.Trace("PhotoCamera: Subscribing to capture events.");

            capture.Started += this.CaptureOnStarted;
            capture.Stopped += this.CaptureOnStopped;

            // Subscribe to a specific capture events.
            // See IPhotoCapture remarks section for details.
            LowLagCapture lowLagCapture = capture as LowLagCapture;

            if (lowLagCapture != null)
            {
                lowLagCapture.PhotoCaptured += this.LowLagCaptureOnPhotoCaptured;
                return;
            }

            VariablePhotoCapture variableCapture = capture as VariablePhotoCapture;

            if (variableCapture != null)
            {
                variableCapture.PhotoCaptured += this.VariableCaptureOnPhotoCaptured;
            }
        }
Beispiel #9
0
        /// <summary>
        /// Unsubscribes from the <paramref name="capture"/> events.
        /// </summary>
        /// <param name="capture">Photo capture.</param>
        private void UnsubscribeFromCaptureEvents(IPhotoCapture capture)
        {
            Tracing.Trace("PhotoCamera: Unsubscribing from capture events.");

            capture.Started -= this.CaptureOnStarted;
            capture.Stopped -= this.CaptureOnStopped;

            LowLagCapture lowLagCapture = capture as LowLagCapture;
            if (lowLagCapture != null)
            {
                lowLagCapture.PhotoCaptured -= this.LowLagCaptureOnPhotoCaptured;
                return;
            }

            VariablePhotoCapture variableCapture = capture as VariablePhotoCapture;
            if (variableCapture != null)
            {
                variableCapture.PhotoCaptured -= this.VariableCaptureOnPhotoCaptured;
            }
        }
Beispiel #10
0
        /// <summary>
        /// Subscribes to the <paramref name="capture"/> events.
        /// </summary>
        /// <param name="capture">Photo capture.</param>
        private void SubscribeToCaptureEvents(IPhotoCapture capture)
        {
            Tracing.Trace("PhotoCamera: Subscribing to capture events.");

            capture.Started += this.CaptureOnStarted;
            capture.Stopped += this.CaptureOnStopped;

            // Subscribe to a specific capture events.
            // See IPhotoCapture remarks section for details.
            LowLagCapture lowLagCapture = capture as LowLagCapture;
            if (lowLagCapture != null)
            {
                lowLagCapture.PhotoCaptured += this.LowLagCaptureOnPhotoCaptured;
                return;
            }

            VariablePhotoCapture variableCapture = capture as VariablePhotoCapture;
            if (variableCapture != null)
            {
                variableCapture.PhotoCaptured += this.VariableCaptureOnPhotoCaptured;
            }
        }
Beispiel #11
0
        /// <summary>
        /// Stops and unloads the current <see cref="photoCapture"/>.
        /// </summary>
        private async Task DestroyPhotoCaptureAsync()
        {
            if (this.photoCapture == null)
            {
                return;
            }

            if (this.captureStarted)
            {
                Tracing.Trace("PhotoCamera: Stopping photo capture.");
                await this.photoCapture.StopAsync();
            }

            Tracing.Trace("PhotoCamera: Unloading photo capture.");
            await this.photoCapture.UnloadAsync();

            this.UnsubscribeFromCaptureEvents(this.photoCapture);
            this.photoCapture = null;
        }
Beispiel #12
0
        /// <summary>
        /// Initializes a new photo capture controller, if needed.
        /// </summary>
        /// <param name="captureMode">Photo capture mode.</param>
        /// <param name="parameters">Camera capture parameters.</param>
        /// <returns>Awaitable task.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="parameters"/> is <see langword="null"/>.</exception>
        /// <exception cref="NotImplementedException"><paramref name="captureMode"/> is not supported.</exception>
        public async Task InitializePhotoCaptureAsync(CaptureMode captureMode, CaptureParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            if (parameters.ImageEncoding == null)
            {
                throw new ArgumentNullException("parameters", "Image encoding is not set.");
            }

            Tracing.Trace("PhotoCamera::InitializePhotoCaptureAsync");

            if (this.photoCapture != null && this.CaptureMode == captureMode && parameters.Equals(this.CaptureParameters))
            {
                Tracing.Trace("PhotoCamera: Capture is already initialized with the same parameters.");
                return;
            }

            this.CaptureMode       = captureMode;
            this.CaptureParameters = parameters;

            await this.DestroyPhotoCaptureAsync();

            this.photoCapture = this.CreatePhotoCapture(captureMode);

            await this.TaskEngine.EnqueueTaskAsync(new InitializePhotoCaptureTask(this.CameraController, this.photoCapture, parameters));
        }
Beispiel #13
0
        public void OnCaptureClicked(object sender, EventArgs args)
        {
            IPhotoCapture camera = DependencyService.Get <IPhotoCapture>();

            camera.Capture();
        }