如何有效地将CALayer转换为CVPixelBuffer?

时间:2019-04-09 02:41:08

标签: calayer cvpixelbuffer

我想找到一种替换CALayer函数“ layer.render(in:context)”的方法,该方法可以更有效地

if let context = CGContext(data: pixelData, width: Int(contextSize.width), height: Int(contextSize.height), bitsPerComponent: 8, bytesPerRow: CVPixelBufferGetBytesPerRow(pixelBuffer), space: rgbColorSpace, bitmapInfo: CGImageAlphaInfo.noneSkipFirst.rawValue) {
    let contentRect = CGRect(x: 0.0, y: 0.0, width: contextSize.width, height: contextSize.height)
    context.clear(contentRect)
    let flipVertical = CGAffineTransform.init(a: 1, b: 0, c: 0, d: -1, tx: 0, ty: contextSize.height)
    context.concatenate(flipVertical)
    // draw the layer in the context
    if let layer = self.delegate?.viedeoLayer?(atTime: Double(currentFrameCount)/Double(frameRate)) {
         //here is the Problem point
         layer.render(in: context)
    }            
   // unlock the buffer memory
   CVPixelBufferUnlockBaseAddress(pixelBuffer, CVPixelBufferLockFlags(rawValue: CVOptionFlags(0)))
}

0 个答案:

没有答案