Exemplo n.º 1
0
        /// <summary>
        /// Captures the image with metadata.
        /// </summary>
        /// <returns>The image with metadata.</returns>
        /// <param name="captureStillImageOutput">Capture still image output.</param>
        /// <param name="connection">Connection.</param>
        private async Task CaptureImageWithMetadata(AVCaptureStillImageOutput captureStillImageOutput, AVCaptureConnection connection)
        {
            var sampleBuffer = await captureStillImageOutput.CaptureStillImageTaskAsync(connection);

            var imageData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);
            var image     = UIImage.LoadFromData(imageData);

            RotateImage(ref image);

            try
            {
                byte[] imgData = image.AsJPEG().ToArray();

                if (Photo != null)
                {
                    Photo(this, imgData);
                }
            }
            catch (Exception error)
            {
                _log.WriteLineTime(_tag + "\n" +
                                   "CaptureImageWithMetadata() Failed to take photo \n " +
                                   "ErrorMessage: \n" +
                                   error.Message + "\n" +
                                   "Stacktrace: \n " +
                                   error.StackTrace);
            }
        }
Exemplo n.º 2
0
        async void TakePicture()
        {
            if (_resetCamera)
            {
                return;
            }

            var videoConnection = _stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await _stillImageOutput.CaptureStillImageTaskAsync(videoConnection);

            var jpegImage = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);

            var picture = new UIImage(jpegImage);

            SetPicture(true, picture);

            NSData  imgData            = picture.AsJPEG();
            NSError err                = null;
            var     documentsDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            var     destinationPath    = System.IO.Path.Combine(documentsDirectory, "picture.jpg");

            if (imgData.Save(destinationPath, false, out err))
            {
                Console.WriteLine("saved as " + destinationPath);
                Callback(destinationPath);
            }
            else
            {
                Console.WriteLine("NOT saved as " + destinationPath + " because" + err.LocalizedDescription);
            }
        }
Exemplo n.º 3
0
        public async Task <OperationResult> SnapStillImage()
        {
            AVCaptureConnection connection = _stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var previewLayer = (AVCaptureVideoPreviewLayer)PreviewLayer;

            // Update the orientation on the still image output video connection before capturing.
            connection.VideoOrientation = previewLayer.Connection.VideoOrientation;

            // Flash set to Auto for Still Capture.
            _videoDeviceInput.Device.SetFlashMode(AVCaptureFlashMode.Auto);

            // Capture a still image.
            try
            {
                var imageDataSampleBuffer = await _stillImageOutput.CaptureStillImageTaskAsync(connection);

                // The sample buffer is not retained. Create image data before saving the still image to the photo library asynchronously.
                NSData imageData = AVCaptureStillImageOutput.JpegStillToNSData(imageDataSampleBuffer);

                if (OnImageSnapped != null)
                {
                    OnImageSnapped(imageData);
                }

                return(OperationResult.AsSuccess());
            }
            catch (NSErrorException ex)
            {
                return(OperationResult.AsFailure(ex));
            }
        }
Exemplo n.º 4
0
        public async Task <byte[]> TakePhoto()
        {
            var session = AVAudioSession.SharedInstance();

            session.SetCategory(AVAudioSessionCategory.Record, AVAudioSessionCategoryOptions.DuckOthers);
            session.SetActive(true);

            NSError nSError;

            aVPlayer = new AVAudioPlayer(new NSUrl("Sounds/5minsilence.mp3"), "mp3", out nSError);
            aVPlayer.FinishedPlaying += delegate {
                aVPlayer = null;
            };
            aVPlayer.Volume = 10f;

            aVPlayer.Play();

            var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);

            var jpegImageAsNsData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);
            var jpegAsByteArray   = jpegImageAsNsData.ToArray();

            return(jpegAsByteArray);
        }
Exemplo n.º 5
0
        public async Task <Stream> CaptureImage()
        {
            var connection   = outputSession.Connections[0];
            var sampleBuffer = await outputSession.CaptureStillImageTaskAsync(connection);

            var imageData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);

            byte[] dataBytes = new byte[imageData.Length];
            System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, dataBytes, 0, Convert.ToInt32(imageData.Length));

            var image    = CIImage.FromData(imageData);
            var metadata = image.Properties.Dictionary.MutableCopy() as NSMutableDictionary;

            ALAssetsLibrary library = new ALAssetsLibrary();

            library.WriteImageToSavedPhotosAlbum(imageData, metadata, (assetUrl, error) =>
            {
                if (error == null)
                {
                    Console.WriteLine("assetUrl:" + assetUrl);
                }
                else
                {
                    Console.WriteLine(error);
                }
            });

            return(new MemoryStream(dataBytes));
        }
Exemplo n.º 6
0
        async partial void TakePhotoButton_TouchUpInside(UIButton sender)
        {
            var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);

            var jpegImageAsNsData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);
            var jpegAsByteArray   = jpegImageAsNsData.ToArray();
        }
Exemplo n.º 7
0
        private async void TakePhotoButton_TouchUpInside(object sender, EventArgs e)
        {
            var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);

            var jpegImageAsNsData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);

            OnPhotoRead(new PhotoEventArgs(requestCode, false, jpegImageAsNsData.ToArray()));
        }
Exemplo n.º 8
0
        public async void CapturePhoto()
        {
            var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);

            var jpegImageAsNsData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);

            await SendPhoto(jpegImageAsNsData.ToArray());
        }
Exemplo n.º 9
0
        public async Task <NSData> CapturePhoto()
        {
            var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);

            var jpegImageAsNsData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);

            return(jpegImageAsNsData);
        }
Exemplo n.º 10
0
        public async Task <byte[]> Capture()
        {
            var buffer = await output.CaptureStillImageTaskAsync(output.Connections[0]);

            NSData imageData = AVCaptureStillImageOutput.JpegStillToNSData(buffer);

            byte[] myByteArray = new byte[imageData.Length];
            System.Runtime.InteropServices.Marshal.Copy(imageData.Bytes, myByteArray, 0, Convert.ToInt32(imageData.Length));
            return(myByteArray);
        }
Exemplo n.º 11
0
        public async Task <byte[]> TakePhoto()
        {
            var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);

            var jpegImageAsNsData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);
            var jpegAsByteArray   = jpegImageAsNsData.ToArray();

            return(jpegAsByteArray);
        }
        private async void CapturePhoto(object sender, EventArgs e)
        {
            var videoConnection = _stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer = await _stillImageOutput.CaptureStillImageTaskAsync(videoConnection);
            var jpegImage = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);

            ViewModel.SetImage(jpegImage.ToArray(), "image/jpeg");

            ViewModel.CloseCommand.Execute(this);
        }
        public async Task CapturePhotoAsync()
        {
            var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);

            var jpegImageAsNsData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);

//			var image = new UIImage (jpegImageAsNsData);
            captureImageView.Image = new UIImage(jpegImageAsNsData);
        }
Exemplo n.º 14
0
        public async Task <UIImage> TakeButtonTapped()
        {
            var videoConnection = captureStillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await captureStillImageOutput.CaptureStillImageTaskAsync(videoConnection);

            var jpegImageAsNsData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);
            var jpegAsByteArray   = jpegImageAsNsData.ToArray();

            return(new UIImage(jpegImageAsNsData));
        }
Exemplo n.º 15
0
        async void CaptureButtonClick(object sender, EventArgs args)
        {
            var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);

            var jpegImageAsNsData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);
            var jpegAsByteArray   = jpegImageAsNsData.ToArray();

            ViewModel.CaptureCommand?.Execute(jpegAsByteArray);
        }
Exemplo n.º 16
0
        async partial void TakePhotoButtonTapped(UIButton sender)
        {
            var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);

            var jpegImageAsNsData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);
            var jpegAsByteArray   = jpegImageAsNsData.ToArray();

            // TODO: Send this to local storage or cloud storage such as Azure Storage.
        }
Exemplo n.º 17
0
        async void CapturePhoto()
        {
            var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);

            var jpegImage = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);

            var photo = new UIImage(jpegImage);

            NSData imgData = photo.AsJPEG(0.8f);

            string timestr = DateTime.Now.Ticks.ToString();

            //The Folllowing is an answer to quesition that how to Get the selected Crop and Image Name
            Models.CropModel SelectedCrop      = null;
            string           selectedImageName = (MainPage as CameraPage).GetViewModel.Parent.SelectedImagePath;

            if ((MainPage as CameraPage).GetViewModel.SelectedCrop != null)
            {
                SelectedCrop = (MainPage as CameraPage).GetViewModel.SelectedCrop;
            }
            //End of


            var documentsDirectory = Environment.GetFolderPath
                                         (Environment.SpecialFolder.MyDocuments);

            var directory = Path.Combine(documentsDirectory, "Photos");

            //string[] files = Directory.GetFiles(directory);

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            string jpgFilename = System.IO.Path.Combine(directory, "NEW_IOS_" + timestr + "_Photo.jpg"); // hardcoded filename, overwritten each time



            NSError err = null;

            if (imgData.Save(jpgFilename, false, out err))
            {
                BigTed.BTProgressHUD.ShowToast("Photo is taken!!!", toastPosition: BigTed.ProgressHUD.ToastPosition.Bottom, timeoutMs: 1200);
                //Console.WriteLine("saved as " + jpgFilename);
            }
            else
            {
                BigTed.BTProgressHUD.ShowToast("Photo is not taken!!!", toastPosition: BigTed.ProgressHUD.ToastPosition.Bottom, timeoutMs: 1200);
                //Console.WriteLine("NOT saved as " + jpgFilename + " because" + err.LocalizedDescription);
            }

            await MainPage.Navigation.PopModalAsync();
        }
Exemplo n.º 18
0
        private async Task <byte[]> CapturePhoto()
        {
            var videoConnection = _avCaptureStillImage.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await _avCaptureStillImage.CaptureStillImageTaskAsync(videoConnection);

            var jpegImageAsNsData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);

            var imageData = jpegImageAsNsData.ToArray();

            return(imageData);
        }
Exemplo n.º 19
0
        private async void CapturePhoto(object sender, EventArgs eventArgs)
        {
            var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);

            var jpegImageAsNsData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);

            var res = await GetCardAsync(requestCode, jpegImageAsNsData.ToArray());

            OnCardRead(res);
        }
Exemplo n.º 20
0
        public async void CapturePhoto()
        {
            var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);

            var jpegImageAsNsData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);

            viewModel.PhotoBytes = jpegImageAsNsData.ToArray();
            viewModel.SavePhotoToAzure();

            await App.Current.MainPage.Navigation.PopModalAsync();
        }
Exemplo n.º 21
0
        public async void CapturePhoto()
        {
            var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);

            //var jpegImageAsBytes = AVCaptureStillImageOutput.JpegStillToNSData (sampleBuffer).ToArray ();
            var jpegImageAsNsData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);
            var image             = new UIImage(jpegImageAsNsData);
            var image2            = new UIImage(image.CGImage, image.CurrentScale, UIImageOrientation.UpMirrored);
            var data = image2.AsJPEG().ToArray();

            ((SelfControl.CameraPage)Element).PictureClickedHandler("", DateTime.Now, (int)image2.Size.Width, (int)image2.Size.Height, data);
        }
Exemplo n.º 22
0
        async void CapturePhoto()
        {
            var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);

            var jpegImage = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);

            var photo = new UIImage(jpegImage);

            photo.SaveToPhotosAlbum((image, error) => {
                Console.Error.WriteLine(@"				Error: ", error);
            });
        }
        private async void TakePhoto(object sender, EventArgs e)
        {
            if (cameraExists)
            {
                var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
                var sampleBuffer    = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);

                CaptureData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);

                RatingMainViewController parentController = ParentViewController as RatingMainViewController;
                parentController?.ActivateSubmitting();
            }
        }
Exemplo n.º 24
0
        public async Task <byte[]> TakePhoto()
        {
            var session = AVAudioSession.SharedInstance();

            session.SetCategory(AVAudioSessionCategory.Record, AVAudioSessionCategoryOptions.DuckOthers);
            session.SetActive(true);

            var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);

            var jpegImageAsNsData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);
            var jpegAsByteArray   = jpegImageAsNsData.ToArray();

            return(jpegAsByteArray);
        }
Exemplo n.º 25
0
        public async void CapturePhoto()
        {
            var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);

            // var jpegImageAsBytes = AVCaptureStillImageOutput.JpegStillToNSData (sampleBuffer).ToArray ();
            var jpegImageAsNsData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);

            // var image = new UIImage (jpegImageAsNsData);
            // var image2 = new UIImage (image.CGImage, image.CurrentScale, UIImageOrientation.UpMirrored);
            // var data = image2.AsJPEG ().ToArray ();

            // SendPhoto (data);
            SendPhoto(jpegImageAsNsData.ToArray());
        }
Exemplo n.º 26
0
        public async void CapturePhoto()
        {
            var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);

            // var jpegImageAsBytes = AVCaptureStillImageOutput.JpegStillToNSData (sampleBuffer).ToArray ();
            var jpegImageAsNsData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);
            var image             = new UIImage(jpegImageAsNsData);

            // We have to rotate the image to portrait, as Apple are weird like that
            var rotated = RotateImage(image);
            var data    = rotated.AsJPEG(0.4f).ToArray();

            // SendPhoto (data);
            SendPhoto(data);
        }
Exemplo n.º 27
0
        async void TakePhotoButton_TouchUpInside(object sender, EventArgs e)
        {
            var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);

            var jpegImageAsNsData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);

            var     path = Path.Combine(System.IO.Path.GetTempPath(), System.IO.Path.GetTempPath() + ".jpg");
            NSError err;

            jpegImageAsNsData.Save(path, false, out err);
            if (err != null)
            {
                path = "";
            }
            Element.SendOnPhotoTaken(path);
        }
Exemplo n.º 28
0
        public async Task CapturePhoto()
        {
            var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);


            var jpegImageAsNsData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);


            var image = new UIImage(jpegImageAsNsData);

            image.SaveToPhotosAlbum(null);

            var toast = new MDToast("Une photo est disponible dans votre bibliothèque", 2);

            toast.Show();
        }
Exemplo n.º 29
0
        async void CapturePhoto()
        {
            var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);

            var jpegImage = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);

            var photo = new UIImage(jpegImage);

            photo.SaveToPhotosAlbum((image, error) =>
            {
                if (!string.IsNullOrEmpty(error?.LocalizedDescription))
                {
                    Console.Error.WriteLine($"\t\t\tError: {error.LocalizedDescription}");
                }
            });
        }
        // This function captures a photo
        public async void CapturePhoto()
        {
            var videoConnection = stillImageOutput.ConnectionFromMediaType(AVMediaType.Video);
            var sampleBuffer    = await stillImageOutput.CaptureStillImageTaskAsync(videoConnection);

            var jpegImageAsNsData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);
            var image             = new UIImage(jpegImageAsNsData);

            this.image = image;

            captureSession.StopRunning();

            retakePictureClick = true;
            var normalAttributedTitle = new NSAttributedString("Retake Picture", foregroundColor: UIColor.White);

            takePhotoButton.SetAttributedTitle(normalAttributedTitle, UIControlState.Normal);
        }