public override void DidOutputSampleBuffer(AVCaptureOutput captureOutput, CMSampleBuffer sampleBuffer, AVCaptureConnection connection) { try { LuminanceSource luminance; using (var pixelBuffer = sampleBuffer.GetImageBuffer() as CVPixelBuffer) { if (bytes == null) { bytes = new byte [pixelBuffer.Height * pixelBuffer.BytesPerRow]; } pixelBuffer.Lock(0); Marshal.Copy(pixelBuffer.BaseAddress, bytes, 0, bytes.Length); luminance = new RGBLuminanceSource(bytes, pixelBuffer.Width, pixelBuffer.Height); pixelBuffer.Unlock(0); } var binarized = new BinaryBitmap(new HybridBinarizer(luminance)); var result = reader.decodeWithState(binarized); //parent.session.StopRunning (); if (parent.QrScan != null) { parent.QrScan(result); } } catch (ReaderException) { // ignore this exception; it happens every time there is a failed scan } catch (Exception e) { // TODO: this one is unexpected.. log or otherwise handle it throw; } finally { try { // lamest thing, but seems that this throws :( sampleBuffer.Dispose(); } catch { } } }