在AVCaptureVideoPreviewLayer上进行绘制需要一些时间才能显示

时间:2018-10-19 18:43:54

标签: ios swift avcapturesession

我有一个 AVCaptureSession 和一个 AVCaptureVideoDataOutput 。我正在绘制一个图层,并将其添加到 captureOutput 方法的预览层中。问题是我的绘制图层需要大约160帧才能显示在预览图层中。从第1帧开始,如何使绘制的图层出现在预览图层中?

func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection){

    i += 1
    print("\(i)")

    layer.removeFromSuperlayer
    layer.path = UIBezierPath(roundedRect: CGRect(x: 64, y: 64, width: 160, height: 160), cornerRadius: 50).cgPath
    layer.fillColor = UIColor.red.cgColor
    previewLayer.layer.addSublayer(layer)

}

0 个答案:

没有答案
相关问题