void CapturePhoto (NSObject sender)
{
// Retrieve the video preview layer's video orientation on the main queue before entering the session queue
// We do this to ensure UI elements are accessed on the main thread and session configuration is done on the session queue
var previewLayer = (AVCaptureVideoPreviewLayer)PreviewView.Layer;
AVCaptureVideoOrientation videoPreviewLayerVideoOrientation = previewLayer.Connection.VideoOrientation;
AVCapturePhotoSettings settings = GetCurrentPhotoSettings ();
sessionQueue.DispatchAsync (() => {
// Update the orientation on the photo output video connection before capturing
AVCaptureConnection photoOutputConnection = photoOutput.ConnectionFromMediaType (AVMediaType.Video);
photoOutputConnection.VideoOrientation = videoPreviewLayerVideoOrientation;
photoOutput.CapturePhoto (settings, this);
});
}