is Connection.Enabled correct way to pause camera for image approval?

h8tow82h8tow82 USUniversity ✭✭

Hi,

I am pausing camera by setting connection.enabled = false to get user approval or rejection.
Seems the image of the taken picture and the last frame displayed are different. Is enabling/disabling connection a right approach?

async partial void TakePhotoButtonTapped (UIButton sender)
        {

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

            (videoPreviewLayer as AVCaptureVideoPreviewLayer).Connection.Enabled = false;

            var alert = new UIAlertView("Pic", "Do you want to use this pic?", null, "No, Retake", "Yes");
            alert.Clicked += (object sender2, UIButtonEventArgs arg) =>
            {
                if (arg.ButtonIndex == 1)
                {
                    var jpegImageAsNsData = AVCaptureStillImageOutput.JpegStillToNSData(sampleBuffer);
                    var jpegAsByteArray = jpegImageAsNsData.ToArray();
                    //.. save here

                    string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                    string filePath = Path.Combine(path, "lastpic7.jpeg");

                    NSError err = null;
                    if (jpegImageAsNsData.Save(filePath, false, out err))
                    {
                        Trace.WriteLine("saved as " + filePath);
                    }
                    else {
                        Trace.WriteLine("NOT saved as " + filePath + " because" + err.LocalizedDescription);
                    }


                }

                (videoPreviewLayer as AVCaptureVideoPreviewLayer).Connection.Enabled = true;

            };
            alert.Show();


        }
Tagged:
Sign In or Register to comment.