Exemplo n.º 1
0
        public async Task<string> TakePhoto()
        {
            if (_capturing)
            {
                return null;
            }

            _capturing = true;

            using (var stream = new InMemoryRandomAccessStream())
            {
                await _mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream);

                var photoOrientation = _displayInformation.ToSimpleOrientation(_deviceOrientation, _mirroringPreview).ToPhotoOrientation();

                if (_mirroringPreview)
                {
                    photoOrientation = PhotoOrientation.FlipHorizontal;
                }

                var photo = await ReencodeAndSavePhotoAsync(stream, photoOrientation);
                PhotoTaken?.Invoke(this, new CameraControlEventArgs(photo));
                _capturing = false;
                return photo;
            }
        }
Exemplo n.º 2
0
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);

            byte[] photo;
            if (resultCode == Result.Ok)
            {
                photo = File.ReadAllBytes(m_photoFileUri.Path);
            }
            else
            {
                photo = null;
            }

            PhotoTaken?.Invoke(this, new PhotoTakenEventArgs(photo));
            Finish();
        }
Exemplo n.º 3
0
        public async Task <string> TakePhoto()
        {
            if (_capturing)
            {
                return("");
            }

            _capturing = true;

            if (_mediaCapture != null)
            {
                if (isAutoFocusCapable)
                {
                    await _mediaCapture.VideoDeviceController.FocusControl.FocusAsync();
                }

                using (var stream = new InMemoryRandomAccessStream())
                {
                    //await _mediaCapture.VideoDeviceController.FocusControl.FocusAsync();
                    await _mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream);

                    var photoOrientation = _displayInformation
                                           .ToSimpleOrientation(_deviceOrientation, _mirroringPreview)
                                           .ToPhotoOrientation(_mirroringPreview);

                    var photo = await ReencodeAndSavePhotoAsync(stream, photoOrientation);

                    PhotoTaken?.Invoke(this, new CameraControlEventArgs(photo));
                    _capturing = false;
                    return(photo);
                }
            }
            else
            {
                return("");
            }
        }