Esempio n. 1
0
        private CameraPreview DispatchOpenWithPreviewAsync(Size previewRequestSize)
        {
            _session.BeginConfiguration();
            var videoOutput = new AVCaptureVideoDataOutput();
            var settings    = new AVVideoSettingsUncompressed {
                PixelFormatType = CVPixelFormatType.CV32BGRA
            };

            videoOutput.UncompressedVideoSetting      = settings;
            videoOutput.WeakVideoSettings             = settings.Dictionary;
            videoOutput.AlwaysDiscardsLateVideoFrames = true;

            var preview = new CameraPreview(previewRequestSize, new System.Drawing.Size(720, 1280));

            videoOutput.SetSampleBufferDelegateQueue(preview, new DispatchQueue("sample buffer"));

            _session.AddOutput(videoOutput);

            var videoConnection = videoOutput.ConnectionFromMediaType(AVMediaType.Video);

            videoConnection.VideoOrientation = AVCaptureVideoOrientation.Portrait;
            videoConnection.VideoMirrored    = true;

            _photoOutput = new AVCapturePhotoOutput
            {
                IsHighResolutionCaptureEnabled = true
            };
            _photoOutput.SetPreparedPhotoSettingsAsync(new[] { CreatePhotoSettings() });

            _session.SessionPreset = AVCaptureSession.Preset1280x720;
            _session.AddOutput(_photoOutput);
            _session.CommitConfiguration();
            _session.StartRunning();
            _isRunning = true;
            return(preview);
        }