// An AutoResetEvent instance is used for drawing metadata object overlays so that
        // only one group of metadata object overlays is drawn at a time.

        MetadataObjectLayer CreateMetadataOverlay(AVMetadataObject metadataObject)
        {
            // Transform the metadata object so the bounds are updated to reflect those of the video preview layer.
            var transformedMetadataObject = PreviewView.VideoPreviewLayer.GetTransformedMetadataObject(metadataObject);

            // Create the initial metadata object overlay layer that can be used for either machine readable codes or faces.
            var metadataObjectOverlayLayer = new MetadataObjectLayer {
                MetadataObject = transformedMetadataObject,
                LineJoin       = CAShapeLayer.JoinRound,
                LineWidth      = 7,
                StrokeColor    = View.TintColor.ColorWithAlpha(0.7f).CGColor,
                FillColor      = View.TintColor.ColorWithAlpha(0.3f).CGColor
            };

            var barcodeMetadataObject = transformedMetadataObject as AVMetadataMachineReadableCodeObject;

            if (barcodeMetadataObject != null)
            {
                var barcodeOverlayPath = BarcodeOverlayPathWithCorners(barcodeMetadataObject.Corners);
                metadataObjectOverlayLayer.Path = barcodeOverlayPath;

                // If the metadata object has a string value, display it.
                if (barcodeMetadataObject.StringValue.Length > 0)
                {
                    var barcodeOverlayBoundingBox = barcodeOverlayPath.BoundingBox;

                    var font      = UIFont.BoldSystemFontOfSize(19).ToCTFont();
                    var textLayer = new CATextLayer {
                        AlignmentMode = CATextLayer.AlignmentCenter,
                        Bounds        = new CGRect(0, 0, barcodeOverlayBoundingBox.Size.Width, barcodeOverlayBoundingBox.Size.Height),
                        ContentsScale = UIScreen.MainScreen.Scale,
                        Position      = new CGPoint(barcodeOverlayBoundingBox.GetMidX(), barcodeOverlayBoundingBox.GetMidY()),
                        Wrapped       = true,

                        // Invert the effect of transform of the video preview so the text is orientated with the interface orientation.
                        Transform        = CATransform3D.MakeFromAffine(PreviewView.Transform).Invert(default(CATransform3D)),
                        AttributedString = new NSAttributedString(barcodeMetadataObject.StringValue, new CTStringAttributes {
                            Font            = font,
                            ForegroundColor = UIColor.White.CGColor,
                            StrokeWidth     = -5,
                            StrokeColor     = UIColor.Black.CGColor
                        })
                    };
                    textLayer.SetFont(font);
                    metadataObjectOverlayLayer.AddSublayer(textLayer);
                }
            }
            else if (transformedMetadataObject is AVMetadataFaceObject)
            {
                metadataObjectOverlayLayer.Path = CGPath.FromRect(transformedMetadataObject.Bounds);
            }
            return(metadataObjectOverlayLayer);
        }
		// An AutoResetEvent instance is used for drawing metadata object overlays so that
		// only one group of metadata object overlays is drawn at a time.

		MetadataObjectLayer CreateMetadataOverlay (AVMetadataObject metadataObject)
		{
			// Transform the metadata object so the bounds are updated to reflect those of the video preview layer.
			var transformedMetadataObject = PreviewView.VideoPreviewLayer.GetTransformedMetadataObject (metadataObject);

			// Create the initial metadata object overlay layer that can be used for either machine readable codes or faces.
			var metadataObjectOverlayLayer = new MetadataObjectLayer {
				MetadataObject = transformedMetadataObject,
				LineJoin = CAShapeLayer.JoinRound,
				LineWidth = 7,
				StrokeColor = View.TintColor.ColorWithAlpha (0.7f).CGColor,
				FillColor = View.TintColor.ColorWithAlpha (0.3f).CGColor
			};

			var barcodeMetadataObject = transformedMetadataObject as AVMetadataMachineReadableCodeObject;
			if (barcodeMetadataObject != null) {
				var barcodeOverlayPath = BarcodeOverlayPathWithCorners (barcodeMetadataObject.Corners);
				metadataObjectOverlayLayer.Path = barcodeOverlayPath;

				// If the metadata object has a string value, display it.
				if (barcodeMetadataObject.StringValue.Length > 0) {
					var barcodeOverlayBoundingBox = barcodeOverlayPath.BoundingBox;

					var font = UIFont.BoldSystemFontOfSize (19).ToCTFont ();
					var textLayer = new CATextLayer {
						AlignmentMode = CATextLayer.AlignmentCenter,
						Bounds = new CGRect (0, 0, barcodeOverlayBoundingBox.Size.Width, barcodeOverlayBoundingBox.Size.Height),
						ContentsScale = UIScreen.MainScreen.Scale,
						Position = new CGPoint (barcodeOverlayBoundingBox.GetMidX (), barcodeOverlayBoundingBox.GetMidY ()),
						Wrapped = true,

						// Invert the effect of transform of the video preview so the text is orientated with the interface orientation.
						Transform = CATransform3D.MakeFromAffine (PreviewView.Transform).Invert (default (CATransform3D)),
						AttributedString = new NSAttributedString (barcodeMetadataObject.StringValue, new CTStringAttributes {
							Font = font,
							ForegroundColor = UIColor.White.CGColor,
							StrokeWidth = -5,
							StrokeColor = UIColor.Black.CGColor
						})
					};
					textLayer.SetFont (font);
					metadataObjectOverlayLayer.AddSublayer (textLayer);
				}
			} else if (transformedMetadataObject is AVMetadataFaceObject) {
				metadataObjectOverlayLayer.Path = CGPath.FromRect (transformedMetadataObject.Bounds);
			}
			return metadataObjectOverlayLayer;
		}