【发布时间】:2016-06-02 14:00:35
【问题描述】:
我尝试写ios相机,我拿了部分代码from apple:
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
// Create a UIImage from the sample buffer data
UIImage *image = [self imageFromSampleBuffer:sampleBuffer];
< Add your code here that uses the image >
}
我需要从程序中的任何位置调用此函数。但是因为它需要创建(CMSampleBufferRef) 的对象类型。怎么做?
我试着写这样的东西:
buf1 = [[CMSampleBufferRef alloc]init]
但这是错误的方式。
【问题讨论】:
-
在您的委托方法中,您不需要创建 CMSampleBuffer 的实例。您会获得对现有缓冲区的引用(sampleBuffer 参数)。
-
@stefos 恕我直言,调用方法需要转换成 3 个参数。还是我错了?
-
这是一个 AVCaptureVideoDataOutputSampleBufferDelegate 方法,在写入新视频帧时调用。您没有显式调用此方法。
-
正如@Xcoder 所说,您不要调用此方法。您只需使用 [captureOutput setSampleBufferDelegate: self queue:] 将控制器设置为委托。
-
@stefos 谢谢。我会考虑的
标签: ios objective-c camera cmsamplebufferref