/// <summary>
        /// Take a new photo and hold it in the output stream.
        /// </summary>
        /// <param name="parameters">The set of parameters used to take the photo, <see cref="ICameraResolution"/> class.</param>
        /// <param name="format">The image format. <see cref="PhotoCaptureFormat"/> enum. </param>
        /// <returns>The <see cref="PhotoCaptureStreamResult"/> struct.</returns>
        public async Task <PhotoCaptureStreamResult> TakePhotoToStreamAsync(ICameraResolution parameters, PhotoCaptureFormat format)
        {
            if (!this.isInitialized)
            {
                Debug.WriteLine("First you need to initialize the videocapturemanager.");
                return(new PhotoCaptureStreamResult());
            }

            try
            {
                if (parameters != null)
                {
                    Debug.WriteLine("Applying paramenters...");
                    await this.mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, (parameters as StreamResolution).EncodingProperties);
                }

                Debug.WriteLine("Taking photo...");
                var stream = new InMemoryRandomAccessStream();

                var properties = this.GetImageEncodingProperties(format);
                await this.mediaCapture.CapturePhotoToStreamAsync(properties, stream);

                Debug.WriteLine("Photo stream loaded.");
                return(new PhotoCaptureStreamResult(true, stream.AsStream()));
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception when taking a photo: " + ex.ToString());
                return(new PhotoCaptureStreamResult(false, Stream.Null));
            }
        }
        /// <summary>
        /// Take a new photo.
        /// </summary>
        /// <param name="filename">The output file name.</param>
        /// <param name="parameters">The set of parameters used to take the photo, <see cref="ICameraResolution"/> class.</param>
        /// <param name="format">The image format. <see cref="PhotoCaptureFormat"/> enum. </param>
        /// <returns>The <see cref="VideoCaptureResult"/> struct.</returns>
        public async Task <PhotoCaptureResult> TakePhotoAsync(string filename, ICameraResolution parameters = null, PhotoCaptureFormat format = PhotoCaptureFormat.JPG)
        {
            PhotoCaptureResult result = default(PhotoCaptureResult);

            if (this.videoCaptureManager != null)
            {
                result = await this.videoCaptureManager.TakePhotoAsync(filename, parameters, format);
            }

            return(result);
        }
        /// <summary>
        /// Take a new photo and hold it in the output stream.
        /// </summary>
        /// <param name="parameters">The set of parameters used to take the photo, <see cref="ICameraResolution"/> class.</param>
        /// <param name="format">The image format. <see cref="PhotoCaptureFormat"/> enum. </param>
        /// <returns>The <see cref="PhotoCaptureStreamResult"/> struct.</returns>
        public async Task <PhotoCaptureStreamResult> TakePhotoInStreamAsync(ICameraResolution parameters = null, PhotoCaptureFormat format = PhotoCaptureFormat.JPG)
        {
            PhotoCaptureStreamResult result = default(PhotoCaptureStreamResult);

            if (this.videoCaptureManager != null)
            {
                result = await this.videoCaptureManager.TakePhotoToStreamAsync(parameters, format);
            }

            return(result);
        }
        /// <summary>
        /// Take a new photo.
        /// </summary>
        /// <param name="filename">The output file name.</param>
        /// <param name="parameters">The set of parameters used to take the photo, <see cref="ICameraResolution"/> class.</param>
        /// <param name="format">The image format. <see cref="PhotoCaptureFormat"/> enum. </param>
        /// <returns>The <see cref="VideoCaptureResult"/> struct.</returns>
        public async Task <PhotoCaptureResult> TakePhotoAsync(string filename, ICameraResolution parameters, PhotoCaptureFormat format)
        {
            if (string.IsNullOrEmpty(filename))
            {
                throw new ArgumentException("The filename cannot be empty or null.");
            }

            if (!this.isInitialized)
            {
                Debug.WriteLine("First you need to initialize the videocapturemanager.");
                return(new PhotoCaptureResult());
            }

            try
            {
                if (parameters != null)
                {
                    Debug.WriteLine("Applying paramenters...");
                    await this.mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, (parameters as StreamResolution).EncodingProperties);
                }

                Debug.WriteLine("Taking photo...");
                var properties = this.GetImageEncodingProperties(format);
                var name       = filename + this.GetFormatExtension(format);
                var file       = await this.captureFolder.CreateFileAsync(name, CreationCollisionOption.GenerateUniqueName);

                Debug.WriteLine("Photo taken! Saving to " + file.Path);
                await this.mediaCapture.CapturePhotoToStorageFileAsync(properties, file);

                Debug.WriteLine("Photo saved.");
                return(new PhotoCaptureResult(true, file.Path));
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception when taking a photo: " + ex.ToString());
                return(new PhotoCaptureResult(false, string.Empty));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Take a new photo.
        /// </summary>
        /// <param name="filename">The output file name.</param>
        /// <param name="parameters">The set of parameters used to take the photo, <see cref="ICameraResolution"/> class.</param>
        /// <param name="format">The image format. <see cref="PhotoCaptureFormat"/> enum. </param>
        /// <returns>The <see cref="VideoCaptureResult"/> struct.</returns>
        public async Task<PhotoCaptureResult> TakePhotoAsync(string filename, ICameraResolution parameters, PhotoCaptureFormat format)
        {
            if (string.IsNullOrEmpty(filename))
            {
                throw new ArgumentException("The filename cannot be empty or null.");
            }

            if (!this.isInitialized)
            {
                Debug.WriteLine("First you need to initialize the videocapturemanager.");
                return new PhotoCaptureResult();
            }

            try
            {
                if (parameters != null)
                {
                    Debug.WriteLine("Applying paramenters...");
                    await this.mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, (parameters as StreamResolution).EncodingProperties);
                }

                Debug.WriteLine("Taking photo...");
                var properties = this.GetImageEncodingProperties(format);
                var name = filename + this.GetFormatExtension(format);
                var file = await this.captureFolder.CreateFileAsync(name, CreationCollisionOption.GenerateUniqueName);

                Debug.WriteLine("Photo taken! Saving to " + file.Path);
                await this.mediaCapture.CapturePhotoToStorageFileAsync(properties, file);

                Debug.WriteLine("Photo saved.");
                return new PhotoCaptureResult(true, file.Path);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception when taking a photo: " + ex.ToString());
                return new PhotoCaptureResult(false, string.Empty);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Take a new photo and hold it in the output stream.
        /// </summary>
        /// <param name="parameters">The set of parameters used to take the photo, <see cref="ICameraResolution"/> class.</param>
        /// <param name="format">The image format. <see cref="PhotoCaptureFormat"/> enum. </param>
        /// <returns>The <see cref="PhotoCaptureStreamResult"/> struct.</returns>
        public async Task<PhotoCaptureStreamResult> TakePhotoToStreamAsync(ICameraResolution parameters, PhotoCaptureFormat format)
        {
            if (!this.isInitialized)
            {
                Debug.WriteLine("First you need to initialize the videocapturemanager.");
                return new PhotoCaptureStreamResult();
            }

            try
            {
                if (parameters != null)
                {
                    Debug.WriteLine("Applying paramenters...");
                    await this.mediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, (parameters as StreamResolution).EncodingProperties);
                }

                Debug.WriteLine("Taking photo...");
                var stream = new InMemoryRandomAccessStream();

                var properties = this.GetImageEncodingProperties(format);
                await this.mediaCapture.CapturePhotoToStreamAsync(properties, stream);

                Debug.WriteLine("Photo stream loaded.");
                return new PhotoCaptureStreamResult(true, stream.AsStream());
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception when taking a photo: " + ex.ToString());
                return new PhotoCaptureStreamResult(false, Stream.Null);
            }
        }